      subroutine sf_z(n,nsf,nmeas,tsa,sf,betap,beta,actm,z,sfb0) 
c bernd berg, nov 27 2008. 
c reweighting of susceptiblibty and structure factors.
c n:     multiplicative factor to convert energy (action) per 
c        degree of freedom to extensive energy (action
c nsf:   number of structure factors considered.
c nmeas: number of measurements in tsa(nmeas) on input. 
c tsa:   energy (action) time series on input.
c sf:    time series of tructure factors 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 sfb0:  numerators of structure factors on output.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension tsa(nmeas),sf(nmeas,nsf),sfb0(nsf)
      ltest=.true.
      ltest=.false.
      if(ltest) stop "tsa_z: ltest."
c
      act=tsa(1) 
      z=exp((betap-beta)*(act-actm)*n)
      do isf=1,nsf
        sfb0(isf)=sf(1,isf)*z
      enddo
      do imeas=2,nmeas
        act=tsa(imeas) 
        zadd=exp((betap-beta)*(act-actm)*n)
        z=z+zadd
        do isf=1,nsf
          sfadd=sf(imeas,isf)*zadd
          sfb0(isf)=sfb0(isf)+sfadd
        enddo 
      enddo
c
      return
      end
