********************************************************************************
*                                                                              *
*  2DHF version 1-2003                                                         *
*  Copyright (C) 1996  Jacek Kobus, Leif Laaksonen, Dage Sundholm              *
*                                                                              *
*  This software may be used and distributed according to the terms            *
*  of the GNU General Public License, see README and COPYING.                  *
*                                                                              *
********************************************************************************
c ### mulex1 ###
c     Last modification: 16/10/00
c
c     This routine generates values of the associate Legendre functions P(k,q)
c     multiplied by [(k-|q|)!/(k+|q|)!]^{1/2} for k=1,..,8 and q=mt. 
c     See also routine which employs the same definition of the functions multi.
c
c     Note that the original routine (mulex) generates values scaled by (-1)**mt

      subroutine mulex1(i,j,mt,dome)
      implicit integer*4 (i-n)
      implicit real*8 (a-h,o-z)
      include 'commons8.inc'
      dimension dome(10)

      do k=1,8
         dome(k)=0.d0
      enddo

      if (mt.gt.4) return

      rr=sqrt(vxisq(j)+vetasq(i)-1.d0)		
      costh=0.d0
      if (abs(rr).gt.precis) then
         costh=veta(i)*vxi(j)/rr	 
      endif

      
      if (mt.eq.0) then
c        m=0
         dome( 1)=costh
         dome( 2)=( 3.d0*costh*dome(1) - 1.d0)	      / 2.d0
         dome( 3)=( 5.d0*costh*dome(2) - 2.d0*dome(1))/ 3.d0
         dome( 4)=( 7.d0*costh*dome(3) - 3.d0*dome(2))/ 4.d0
         dome( 5)=( 9.d0*costh*dome(4) - 4.d0*dome(3))/ 5.d0
         dome( 6)=(11.d0*costh*dome(5) - 5.d0*dome(4))/ 6.d0
         dome( 7)=(13.d0*costh*dome(6) - 6.d0*dome(5))/ 7.d0
         dome( 8)=(15.d0*costh*dome(7) - 7.d0*dome(6))/ 8.d0
         return
      elseif (mt.eq.1) then
c        m=1
         costh2=costh*costh
         costh4=costh2*costh2
         costh6=costh4*costh2

         sini2=abs(1.d0-costh2)
         sini =sqrt(sini2)

         dome(1)=-sini/sqrt(2.d0)
         dome(2)=-3.d0*sini*costh/sqrt(6.d0)
         dome(3)=(3.d0/2.d0)*sini*(1.d0-5.d0*costh2)/sqrt(12.d0)
         dome(4)=(5.d0/2.d0)*sini*costh
     &        *(3.d0-7.d0*costh2)/sqrt(20.d0)
         dome(5)=(15.d0/8.d0)*sini
     &        *(-1.d0+14.d0*costh2-21.d0*costh4)/sqrt(30.d0)
         dome(6)=(21.d0/8.d0)*sini*costh
     &        *(-5.d0+30.d0*costh2-33.d0*costh4)/sqrt(42.d0)
         dome(7)=(7.d0/16.d0)*sini
     &        *(5.d0-135.d0*costh2+495.d0*costh4
     &        -429.d0*costh6)/sqrt(56.d0)
         dome(8)=(9.d0/16.d0)*sini*costh*(35.d0-385.d0*costh2
     &        +1001.d0*costh4-715.d0*costh6)/sqrt(72.d0)

         return
      elseif (mt.eq.2) then
c        m=2
         costh2=costh*costh
         costh4=costh2*costh2
         costh6=costh4*costh2
         costh8=costh6*costh2
         
         sini2=abs(1.d0-costh2)

         dome(1)=0.d0
         dome(2)=3.d0*sini2/sqrt(24.d0)
         dome(3)=15.d0*costh*sini2/sqrt(120.d0)
         dome(4)=(15.d0/2.d0)*(-1.d0+8.d0*costh2
     &        -7.d0*costh4)/sqrt(360.d0)
         dome(5)=(105.d0/2.d0)*costh*(-1.d0+4.d0*costh2
     &        -3.d0*costh4)/sqrt(840.d0)
         dome(6)=(105.d0/8.d0)
     &        *(1.d0-19.d0*costh2+51.d0*costh4
     &        -33.d0*costh6)/sqrt(1680.d0)
         dome(7)=(63.d0/8.d0)*costh
     &        *(15.d0-125.d0*costh2+253.d0*costh4
     &        -143.d0*costh6)/sqrt(3024.d0)
         dome(8)=(315.d0/8.d0)*(-1.d0+34.d0*costh2-176.d0*costh4
     &        +286.d0*costh6-143.d0*costh8)/sqrt(5040.d0)
         return
      elseif (mt.eq.3) then 
c        m=3
         costh2=costh*costh
         costh4=costh2*costh2

         sini2=abs(1.d0-costh2)
         sini =sqrt(sini2)
         sini3=sini2*sini

         dome(1)=0.d0
         dome(2)=0.d0
         dome(3)=-15.d0*sini3/sqrt(720.d0)
         dome(4)=-105.d0*sini3*costh/sqrt(5040.d0)
         dome(5)=-(105.d0/2.d0)*sini3
     &        *(-1.d0+9.d0*costh2)/sqrt(20160.d0)
         dome(6)=-(315.d0/2.d0)*sini3*costh
     &        *(-3.d0+11.d0*costh2)/sqrt(60480.d0)
         dome(7)=-(315.d0/8.d0)*sini3
     &        *(3.d0-66.d0*costh2+143.d0*costh4)/sqrt(151200.d0)
         dome(8)=-(3465.d0/8.d0)*sini3*costh
     &        *(3.d0-26.d0*costh2+39.d0*costh4)/sqrt(332640.d0)
         return
      elseif (mt.eq.4) then
c        m=4
         costh2=costh*costh
         costh4=costh2*costh2
         costh6=costh4*costh2
         costh8=costh6*costh2

         dome(1)=0.d0
         dome(2)=0.d0
         dome(3)=0.d0
         dome(4)=105.d0*(1.d0-2.d0*costh2+costh4)/sqrt(40320.d0)
         dome(5)=945.d0*costh*(1.d0-2.d0*costh2+costh4)/sqrt(362880.d0)
         dome(6)=(945.d0/2.d0)
     &        *(-1.d0+13*costh2-23.d0*costh4
     &        +11.d0*costh6)/sqrt(1814400.d0)
         dome(7)=(3465.d0/2.d0)*costh
     &        *(-3.d0+19*costh2-29.d0*costh4
     &        +13.d0*costh6)/sqrt(6652800.d0)
         dome(8)=(10395.d0/8.d0)*(1.d0-28.d0*costh2+118.d0*costh4
     &        -156.d0*costh6+65.d0*costh8)/sqrt(19958400.d0)
      endif
      return	
      end

