      subroutine smetupdt(phinn,xmfactor,xla,dphi,phi1,phisum,
     &                    sactnn,sact2,sact,acpt)
C Bernd Berg Feb 20 2012. Metropolis update of scalar field.
C On input only:  phinn    sum  of nearest-neighbor fields.
C                 xmfactor coupling factor in quadratic term.
C                 dphi     [-dphi,dphi] range for proposal.
C On input and updated on output:
C                 phi1     field at considered site.
C                 phisum   summed fields.
C                 sact     action.
C                 acpt     acceptance rate.
C On Output: sact      action difference.
C            iacpt      0 proposal rejection, 1 proposal acceptance.
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      data icnt/0/
      save icnt
      icnt=icnt+1
      call sactphi1(actonn,aophi2,phinn,xmfactor,xla,phi1) 
      sact1o=actonn-aophi2 ! Old action at site.
      phin=phi1+dphi*(two*rmafun()-one) !  n=new: Proposed field.
      call sactphi1(actnnn,anphi2,phinn,xmfactor,xla,phin) 
      sact1n=actnnn-anphi2 ! New action at site.
      dsact=sact1n-sact1o
      if(dsact.lt.zero) then
        if(exp(dsact).lt.rmafun()) return ! Rejection.
      endif
      phisum=phisum+phin-phi1
      sact=sact+dsact
      sactnn=sactnn-actonn+actnnn
      sact2=sact2-aophi2+anphi2
      acpt=acpt+one 
      phi1=phin
      return ! Acceptance.
      end
