aboutsummaryrefslogtreecommitdiff
path: root/src/phif.F
blob: 13a7bbd8783db589f65b0df7c5bd18864f56d221 (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
48
49
50
51
52
/*@@
  @file      phif.F
  @date      October 1998
  @author    Miguel Alcubierre
  @desc
             Function to find angle phi from coordinates {x,y}.
  @enddesc
  @version   $Header$
@@*/

#include "cctk.h"

      CCTK_REAL function phif(x,y)

      implicit none

      CCTK_REAL x,y
      CCTK_REAL zero,half,one,two,pi

c     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 (abs(x).gt.abs(y)) then
         phif = atan(abs(y/x))
      else if (abs(x).lt.abs(y)) then
         phif = half*pi - atan(abs(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