********************************************************************************
*                                                                              *
*  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 ### plegendg ###		  	    
c
c
      function plegendg(l,m,costh)
      implicit integer*4 (i-n)
      implicit real*8 (a-h,o-z)		
      include 'commons8.inc'

      ct=abs(1.d0-costh*costh)
      
      if (m.eq.0) then
         plegendg=hypgf3(-l,l+1,1,(1.d0-costh)/2.d0)
      elseif (m.ne.0.and.ct.lt.precis) then           
         plegendg=0.d0
      else
         fn0=(-1.d0**m)*factor(l+m)/factor(l-m)
     &        /factor(m)/(2.d0**m)
         ct1=fn0*ct**(dble(m)/2.d0)	   
         plegendg=hypgf3(m-l,m+l+1,m+1,(1.d0-costh)/2.d0)*ct1
      endif
      return
      end
