      subroutine scalar_actdif(sact0,phisum0,phi,xmfactor,xla,ipf,ns,nd,
     &  sactdif,phisdif) ! Bernd Berg Feb 19 2012. 
C Calculates action and phisum differences for scalar field.
C Iterated action sact0 and phisum0 on input. Aborts if 
C discrepancy with direct calculation is found (set eps!). 
C Returns sact0=sact and sactdif relative errors.
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      parameter(eps=one/10**7)
      dimension phi(ns),ipf(nd,ns)
      call scalar_act(phi,xmfactor,xla,ipf,ns,nd,
     &  sactnn,sact2,sact,phisum) 
      sactdif=abs((sact0-sact)/sact) 
      phisdif=abs((phisum0-phisum)/phisum) 
      if(sactdif.gt.eps.or.phisdif.gt.eps) then
        write(6,'(/," scalar_actdif:")')
        write(6,'(" Discrepancy with direct calculation.")')
        write(6,'(" sact0,sact:    ",2G20.12)') sact0,sact
        write(6,'(" phisum0,phisum:",2G20.12)') phisum0,phisum
        write(6,'(" Relative errrors:")')
        write(6,'(" sactdif,phisdif,eps:",3G15.5)') sactdif,phisdif,eps
      stop "scala_actdif: Discrepancy between action calculations."
      endif
      sact0=sact
      phisum0=phisum
      return
      end
