      subroutine scalar0_cor(imeas) ! Bernd Berg Mar 29 2009. 
C Measurement of correlations functions.
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      include '../../Libs/Fortran_par/lat0.par'
      include '../../Libs/Fortran_par/mc.par'
      include '../../Libs/Fortran_par/common_lat.f'
      include '../../Libs/Scalar_par/common_scalar0.f'
      ltest=.true.
      ltest=.false.
      if(imeas.eq.1) then
        do it=0,mt
          phi0sum(it)=zero
        enddo
        do idel=0,mth
          cor0(idel)=zero
          cor1r(idel)=zero
          cor1i(idel)=zero
        enddo
      endif
C
      do it=1,mt ! Operators.
        phi0(it)=zero
        phi1r(it)=zero
        phi1i(it)=zero
        ix=0
        do ixs=1,mxs
          ix=ix+1
          phi1=phi(ixs+(it-1)*mxs)
          phi0(it)=phi0(it)+phi1
          phi1r(it)=phi1r(it)+phi1*xkr(ix)
          phi1i(it)=phi1i(it)+phi1*xki(ix)
          if(ix.eq.ml) ix=0
        enddo
        phi0(it)=phi0(it)/mxs ! Inconsistent with phi1 normalization.
        phi0sum(it)=phi0sum(it)+phi0(it)
      enddo
C
      do idel=0,mth ! Correlation function.
        do it1=1,mt
          it2=it1+idel
          if(it2.gt.mt) it2=it2-mt
          cor0(idel)=cor0(idel)+phi0(it1)*phi0(it2)
          cor1r(idel)=cor1r(idel)+phi1r(it1)*phi1r(it2)
          cor1i(idel)=cor1i(idel)+phi1i(it1)*phi1i(it2)
        enddo
      enddo
C
      if(imeas.eq.nmeas) then ! Normalization.
        do it=0,mt
          phi0sum(it)=phi0sum(it)/nmeas
        enddo
        do idel=0,mth
          cor0(idel)=cor0(idel)/nmeas
          cor1r(idel)=cor1r(idel)/nmeas
          cor1i(idel)=cor1i(idel)/nmeas
        enddo
      endif
      if(ltest) then
        write(iuo,'(2X,"scalar_cor done.",/)')
      stop "scalar_cor: ltest"
      endif
      return
      end
