      subroutine vec_unit(nd,v,u,xn) ! bernd berg jun 16 2008.  
c returns unit vector u in direction of v and xn=|v|.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension v(nd),u(nd)
      xn=zero
      do id=1,nd
        xn=xn+v(id)**2
      enddo
      xn=sqrt(xn)
      xni=one/xn
      do id=1,nd
        u(id)=xni*v(id)
      enddo
      return
      end
