The Elk Code
sphcover.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2008 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
3 ! This file is distributed under the terms of the GNU Lesser General Public
4 ! License. See the file COPYING for license details.
5 
6 !BOP
7 ! !ROUTINE: sphcover
8 ! !INTERFACE:
9 subroutine sphcover(n,tp)
10 ! !INPUT/OUTPUT PARAMETERS:
11 ! n : number of required points (in,integer)
12 ! tp : (theta, phi) coordinates (out,real(2,n))
13 ! !DESCRIPTION:
14 ! Produces a set of $N$ points which cover the unit sphere nearly optimally.
15 ! The points in spherical $(\theta,\phi)$ coordinates are generated using the
16 ! explicit `golden section' formula:
17 ! \begin{align*}
18 ! \theta_k&=\arccos\left[1-\left(k-\tfrac{1}{2}\right)\delta z\right] \\
19 ! \phi_k&=(k-1)\delta\phi,
20 ! \end{align*}
21 ! where $\delta z=2/n$ and $\delta\phi=\pi(1-\sqrt{5})$.
22 !
23 ! !REVISION HISTORY:
24 ! Created April 2008 (JKD)
25 ! Improved covering, October 2009 (JKD)
26 !EOP
27 !BOC
28 implicit none
29 ! arguments
30 integer, intent(in) :: n
31 real(8), intent(out) :: tp(2,n)
32 ! local variables
33 integer k
34 real(8), parameter :: pi=3.1415926535897932385d0
35 real(8) z,dz,p,dp
36 if (n < 1) then
37  write(*,*)
38  write(*,'("Error(sphcover): n < 1 : ",I8)') n
39  write(*,*)
40  stop
41 end if
42 dz=2.d0/dble(n)
43 z=1.d0-dz/2.d0
44 tp(1,1)=acos(z)
45 dp=pi*(1.d0-sqrt(5.d0))
46 p=0.d0
47 tp(2,1)=p
48 do k=2,n
49  z=z-dz
50  tp(1,k)=acos(z)
51  p=p+dp
52  tp(2,k)=mod(p,2.d0*pi)
53 end do
54 end subroutine
55 !EOC
56 
subroutine sphcover(n, tp)
Definition: sphcover.f90:10