c    @(#)rmsd.f	1.1
c
c
c
      real function rmsd(n,a,b)
      dimension a(n),b(n)
      real mean
c
      rmsd=0.0
      rms=0.0
      mean=0.0
      do 10 ip=1,n
        rmsd=rmsd+(a(ip)-b(ip))**2.
        rms=rms+(b(ip))**2.
        mean=mean+b(ip)
   10 continue
      mean=mean/n
      rms=rms-n*mean**2.
      rms=max(rms,0.0)
      if(rms.ne.0.0)rmsd=sqrt(rmsd/rms)
      if(rms.eq.0.0.and.rmsd.eq.0.0)rmsd=0.0
      if(rms.eq.0.0.and.rmsd.ne.0.0)rmsd=1.0
      return
c
c
      end
