      subroutine vec_schmidt2(nd,v1,v2,u1,u2,v1n,vp2n,u1dotv2)
c bernd berg jun 21 2008.
c schmidt construction of orthonormal system for two vectors v1, v2.
c v1, v2  are unchanged on output.
c returns: unit vectors u1, u2, norm v1n of v1, norm vp2n of 
c perpendicular part of v2, and dotproduct (u1,v2).
      include '../../libs/fortran/implicit.sta'  
      include '../../libs/fortran/constants.par'
      dimension v1(nd),v2(nd),u1(nd),u2(nd)
      call vec_unit(nd,v1,u1,v1n)
      u1dotv2=vec_dot(nd,u1,v2) 
      do id=1,nd
        u2(id)=v2(id)-u1dotv2*u1(id)
      enddo
      call vec_unit(nd,u2,u2,vp2n)
      return
      end

