      subroutine lsdvharm(m,j2,n,np,vrad,vhor,vtor,parity)

C*******************************************************
C
C This subroutine sets up the radial, horizontal and
C toroidal expansion vectors for use by the lsd function
C routines, as they would be for a spehrical harmonic of
C m-value m, j-value j2 and parity parity.
C 
C Started:4/12/95
C
C (c) Richard Townsend 1995
C
C********************************************************

      implicit none

C Declare the passed parameters

      integer m			! The m-value to do the vectors for
      integer j2 		! The j-value to do the vectors for
      integer n			! The dimension of the vectors
      integer np		! The physical dimentsion of the vectors
      double precision vrad(np)	! The radial expansion vector
      double precision vhor(np) !The horizontal expansion vector
      double precision vtor(np) ! The toroidal expansion vector (all zeros)
      logical parity   ! The parity of the mode to do

C Declare the in-program variables
 
      integer j			! Counter to loop through the vectors
      integer am		! The absolute value of m
      double precision parfac   ! The partial factorial function (l+|m|)...(l-|m|)

C Set up am=|m|

      am=iabs(m)

C Loop over j to get the coefficients...

      do j=1,n

C If j=j2, set the vectors up as usual - otherwise, zero them

      if(j.eq.j2) then

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

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

      else
        vrad(j)=0.D0
        vhor(j)=0.D0
        vtor(j)=0.D0
      endif

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

      enddo

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

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

C Thats all folks - return...

      return

      end

