aboutsummaryrefslogtreecommitdiff
path: root/src/phif.F
blob: c24f2ca210eee46d4bf616a6e42faf57303dd50d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "cctk.h"

      CCTK_REAL function phif(x,y)

c     Author: Miguel Alcubierre, October 1998.
c
c     Function to find angle phi from coordinates {x,y}.

      implicit none

      CCTK_REAL x,y
      real*8 zero,half,one,two,pi

c     Define numbers.

      zero = 0.0D0
      half = 0.5D0
      one  = 1.0D0
      two  = 2.0D0

      pi = acos(-one)

c     Find angle between 0 and pi/2 such that tan(phi) = |y/x|.

      if (dabs(x).gt.dabs(y)) then
         phif = atan(dabs(y/x))
      else if (dabs(x).lt.dabs(y)) then
         phif = half*pi - atan(dabs(x/y))
      else
         phif = 0.25D0*pi
      end if

c     Use signs of {x,y} to move to correct quadrant.

      if ((x.eq.zero).and.(y.eq.zero)) then
         phif = zero
      else if ((x.le.zero).and.(y.ge.zero)) then
         phif = pi - phif
      else if ((x.le.zero).and.(y.le.zero)) then
         phif = pi + phif
      else if ((x.ge.zero).and.(y.le.zero)) then
         phif = two*pi - phif
      end if

      return
      end