- #1
nepapak
- 4
- 0
Hey guys I am trying to understand a code for a Fortran 77 subroutine which calculates spherical harmonics using the CERN library RASLGF for legendre functions. The code looks like this
subroutine harmonics(max,theta,phi,Yr,Yi)
implicit none
integer max,k,nn,n,grens
double precision x,theta,phi,ct,nphi,pi
double precision leg(0:max)
double precision Yr(0:max,0:(2*max)),Yi(0:max,0:(2*max))
parameter (pi=3.141592654)
do k=0,max
do n=0,2*max
Yr(k,n)=0.
Yi(k,n)=0.
enddo
enddo
ct=cos(theta)
do nn=-max,max
nphi=nn*phi
grens=abs(nn)
call DASLGF(2,ct,nn,max,leg) ! calculates the associated Legendre
! functions
do k=grens,max
n=nn+k
if (nn.lt.0) then !different definition for leg(k) with n neg
leg(k)=((-1)**nn)*leg(k)
endif
Yr(k,n)=((-1)**(nn)/sqrt(2*pi))*cos(nphi)*leg(k) !p(k)=P_k^n
Yi(k,n)=((-1)**(nn)/sqrt(2*pi))*sin(nphi)*leg(k)
enddo
enddo
return
end
Now there are two parts I don't understand. Why is this line written leg(k)=((-1)**nn)*leg(k) when it says in the description of the RASLGF library that it is permisable for n to be negative?
Second problem is why is there a ((-1)**(nn)/sqrt(2*pi)) multiplier for Yr(k,n) and Yi(k,n)? I have looked at a lot of definitions for spherical harmonics but I just can't seem to find any reference for such a multiplier.
subroutine harmonics(max,theta,phi,Yr,Yi)
implicit none
integer max,k,nn,n,grens
double precision x,theta,phi,ct,nphi,pi
double precision leg(0:max)
double precision Yr(0:max,0:(2*max)),Yi(0:max,0:(2*max))
parameter (pi=3.141592654)
do k=0,max
do n=0,2*max
Yr(k,n)=0.
Yi(k,n)=0.
enddo
enddo
ct=cos(theta)
do nn=-max,max
nphi=nn*phi
grens=abs(nn)
call DASLGF(2,ct,nn,max,leg) ! calculates the associated Legendre
! functions
do k=grens,max
n=nn+k
if (nn.lt.0) then !different definition for leg(k) with n neg
leg(k)=((-1)**nn)*leg(k)
endif
Yr(k,n)=((-1)**(nn)/sqrt(2*pi))*cos(nphi)*leg(k) !p(k)=P_k^n
Yi(k,n)=((-1)**(nn)/sqrt(2*pi))*sin(nphi)*leg(k)
enddo
enddo
return
end
Now there are two parts I don't understand. Why is this line written leg(k)=((-1)**nn)*leg(k) when it says in the description of the RASLGF library that it is permisable for n to be negative?
Second problem is why is there a ((-1)**(nn)/sqrt(2*pi)) multiplier for Yr(k,n) and Yi(k,n)? I have looked at a lot of definitions for spherical harmonics but I just can't seem to find any reference for such a multiplier.