Nbody6
 All Files Functions Variables
nbsort.f
Go to the documentation of this file.
1  SUBROUTINE nbsort(NBL,IBL,NNB,NBLIST)
2 *
3 *
4 * Sorting of neighbour lists.
5 * ---------------------------
6 *
7  include 'common6.h'
8  INTEGER ibl(lmax),nblist(nmax),lp(nmax)
9 *
10 *
11 * Initialize counter and list pointers.
12  nnb = 0
13  DO 1 l = 1,nbl
14  lp(l) = 2
15  1 CONTINUE
16 *
17 * Reset terminator count and minimum particle index.
18  5 iend = 0
19  jmin = ntot + 1
20 *
21 * Compare current location of all neighbour lists.
22  DO 10 ll = 1,nbl
23  i = ibl(ll)
24  l = lp(ll)
25 * Check each list member or count completed searches.
26  IF (l.LT.list(1,i) + 2) THEN
27  j = list(l,i)
28  IF (j.LT.jmin) THEN
29  jmin = j
30  lmin = ll
31 * Update pointer for all J <= JMIN (except latest JMIN).
32  ELSE IF (j.LE.jmin) THEN
33  lp(ll) = lp(ll) + 1
34  END IF
35  ELSE
36  iend = iend + 1
37  END IF
38  10 CONTINUE
39 *
40 * Increase pointer & membership and save new index in NBLIST.
41  IF (iend.LT.nbl) THEN
42  lp(lmin) = lp(lmin) + 1
43  nnb = nnb + 1
44  nblist(nnb) = jmin
45  go to 5
46  END IF
47 *
48 * Exit on rare case of one member with zero neighbours (10/2008).
49  IF (nnb.EQ.0) go to 70
50 *
51 * Add any integration particles missing from joint neighbour lists.
52  new = 0
53  fac = nnb/float(ntot)
54  l = 1
55  20 i = ibl(l)
56 * Skip search if body #I is outside the list range.
57  IF (nblist(1).GT.i.OR.nblist(nnb).LT.i) go to 50
58  IF (nblist(1).EQ.i.OR.nblist(nnb).EQ.i) go to 60
59 *
60 * Search sequential list using incremental expectation values (> 0).
61  ig = i*fac
62  ig = max(ig,1)
63  30 IF (nblist(ig).GT.i) THEN
64  inc = (nblist(ig) - i)*fac
65  inc = min(inc,3)
66  IF (inc.LE.1) THEN
67  ig = ig - 1
68  IF (nblist(ig).LT.i) go to 50
69  ELSE
70  ig = ig - inc
71  ig = max(ig,1)
72  IF (nblist(ig).LT.i) THEN
73  ig = ig + inc - 1
74  IF (nblist(ig).GT.i) THEN
75  ig = ig - 1
76  IF (nblist(ig).GT.i) ig = ig - 1
77  END IF
78  ELSE
79  IF (nblist(ig).GT.i) THEN
80  ig = ig - 1
81  IF (nblist(ig).GT.i) ig = ig - 1
82  END IF
83  END IF
84  END IF
85  go to 30
86  END IF
87 *
88 * Treat case of NBLIST < I until boundary exceeded or NBLIST > I.
89  40 IF (nblist(ig).LT.i) THEN
90  inc = (i - nblist(ig))*fac
91  inc = max(inc,1)
92  ig = ig + inc
93  IF (ig.GE.nnb) THEN
94  IF (nblist(nnb).EQ.i) go to 60
95  go to 50
96  END IF
97  IF (inc.EQ.1) THEN
98  IF (nblist(ig).GT.i) go to 50
99  END IF
100 * Reduce index by 1 to avoid resonance oscillations (NBLIST > I).
101  45 IF (nblist(ig).GT.i) THEN
102  ig = ig - 1
103  IF (nblist(ig).LT.i) go to 50
104  go to 45
105  END IF
106  go to 40
107  END IF
108 *
109 * Skip addition if body #I is already a member (NBLIST(IG) = I).
110  go to 60
111 *
112 * Increase counter and add body #I at end of array.
113  50 new = new + 1
114  nblist(nnb+new) = i
115 *
116 * Continue until last body has been checked.
117  60 l = l + 1
118  IF (l.LE.nbl) go to 20
119 *
120 * Specify the total membership (Note: new members not sequential).
121  nnb = nnb + new
122 *
123  70 RETURN
124 *
125  END