      subroutine lsdvhor(vhor,m,eigval,n,np,
     :                  bvec,parity)

C***************************************************
C
C This function sets up a vector vhor which is used
C as a set of expansion coefficients in the calculation
C of the horizontal velocity
C function of Lee & Saio's Lambda basis (ApJ 1990)
C The horizontal (neglecting toroidal) velocity field
C of an NRP eigenstate is then the horizontal gradient
C of this function. The routine uses the eigenvector for
C the mode in question bvec, and also the eigenvale eigval.
C See lsdfhor for details....
C
C Stated:3/7/95
C Last Modified:4/12/95
C
C (c) Richard Townsend 1995
C
C*****************************************************

      implicit none		! Turn off implicit typing

C Declare the passed variables

      double precision eigval	! The eigenvalue corresponding to bvec
      integer m			! The m-value to use
      integer n			! The number of terms to sum over
      integer np		! The total size of bvec
      double precision bvec(np)	! The column vector containing the approp. eigenvector
      double precision vhor(np) ! The column vector containing the expansion coefficients
      logical parity		! The parity to be used - .true.=even

C Declare the in-program variables

      integer j			! The coefficient index
      integer am		! The absoulte value of m
      double precision parfac	! The partial factorial (l+|m|)...(l-|m|+1)

C Set up am=|m|
                             
      am=iabs(m)      

C And now loop over j to get the coefficients...

      do j=1,n

C We set the jth coefficient, depending on whether the parity
C is even (.true.) or odd (.false.)

        if(parity) then
          vhor(j)=eigval*bvec(j)*
     :     dsqrt((am+2*(j-1)+0.5D0)/
     :     parfac(am+2*(j-1),am))/
     :     ( (am+2*(j-1))*(am+1+2*(j-1)) )
        else
          vhor(j)=eigval*bvec(j)*
     :     dsqrt((am+2*(j-1)+1.5D0)/
     :     parfac(am+1+2*(j-1),am))/
     :     ( (am+1+2*(j-1))*(am+2+2*(j-1)) )
        endif

C Its as simple as that - now loop back around....

      enddo

C As a little safety check, we zero all the remaining coeffs...

      do j=n+1,np
        vhor(j)=0.D0
      enddo

C Thats all folks - return...

      return

      end
