Nbody6
 All Files Functions Variables
binout.f
Go to the documentation of this file.
1  SUBROUTINE binout
2 *
3 *
4 * Binary analysis & output.
5 * -------------------------
6 *
7  include 'common6.h'
8  common/echain/ ech
9  INTEGER jd(15),jeb(15),je(10)
10 *
11 *
12 * Define semi-major axis & binding energy of hard binary (= KT).
13  a0 = 1.0/float(nzero)
14  eb0 = -0.25/float(nzero)
15 * Initialize counters & variables.
16  DO 10 j = 1,15
17  jd(j) = 0
18  jeb(j) = 0
19  10 CONTINUE
20  DO 20 j = 1,10
21  je(j) = 0
22  20 CONTINUE
23  ebmax = 0.0
24  disp = 0.0
25  emax = 0.0
26  jor = 0
27  jex = 0
28  jc = 0
29  jlast = 0
30  klast = 0
31  e(1) = 0.0d0
32  e(2) = 0.0d0
33  npop(1) = 0
34  npop(2) = 0
35  npop(3) = n - 2*npairs
36  newb = 0
37  k10 = 0
38 *
39 * Obtain relevant distributions of KS binaries.
40  DO 50 j = 1,npairs
41  i = n + j
42  IF (h(j).GE.0.0.OR.body(i).EQ.0.0d0) go to 50
43  j1 = 2*j - 1
44  j2 = 2*j
45 *
46 * Count original & exchanged binaries and core members.
47  IF (iabs(name(j1) - name(j2)).EQ.1) THEN
48  IF (name(j1).LE.2*nbin0) jor = jor + 1
49  ELSE
50  IF (min(name(j1),name(j2)).LE.2*nbin0) jex = jex + 1
51  END IF
52  ri2 = (x(1,i) - rdens(1))**2 + (x(2,i) - rdens(2))**2 +
53  & (x(3,i) - rdens(3))**2
54  IF (ri2.LT.rc2) jc = jc + 1
55 *
56 * Adopt logarithmic distribution of semi-major axis (factor 2).
57  semi = -0.5d0*body(i)/h(j)
58  IF (semi.LT.a0) THEN
59  k = 2 + log10(a0/semi)/log10(2.0)
60  k = min(k,10)
61  jlast = max(jlast,k)
62  jd(k) = jd(k) + 1
63  ELSE
64  jd(1) = jd(1) + 1
65  END IF
66 *
67 * Form eccentricity dispersion & histogram.
68  ecc2 = (1.0 - r(j)/semi)**2 + tdot2(j)**2/(body(i)*semi)
69  disp = disp + ecc2
70  IF (ecc2.GT.emax) emax = ecc2
71  k = 1 + 10.0*sqrt(ecc2)
72  IF (k.LE.10) je(k) = je(k) + 1
73 *
74 * Set up logarithmic distribution of binding energy (factor 2).
75  eb = -0.5*body(j1)*body(j2)/semi
76  IF (eb.LT.eb0) THEN
77  k = 2 + log10(eb/eb0)/log10(2.0)
78  k = min(k,14)
79  klast = max(klast,k)
80  jeb(k) = jeb(k) + 1
81  ebmax = min(ebmax,eb)
82  ELSE
83  jeb(1) = jeb(1) + 1
84  END IF
85 *
86 * Define flag to distinguish primordial or non-primordial binary.
87  ip = 1
88  IF (list(2,j2).EQ.0) ip = 2
89  IF (ip.EQ.2) newb = newb + 1
90 *
91 * Sum the respective energies & populations.
92  e(ip) = e(ip) + eb
93  npop(ip) = npop(ip) + 1
94 *
95 * Perform consistency check in case of over-writing.
96  IF (list(2,j2).NE.-1.AND.list(2,j2).NE.0) THEN
97  WRITE (6,35) j, list(1,j1), list(1,j2), list(2,j2),
98  & name(n+j)
99  35 FORMAT (/,5x,'WARNING! FLAG PROBLEM PAIR NP NP2 FLAG',
100  & ' NAME ',5i6)
101  END IF
102 *
103 * Produce special diagnostics for new binaries (unit 18).
104  IF (ip.EQ.2.AND.h(j).LT.0.0) THEN
105  vr = ((x(1,i) - rdens(1))*xdot(1,i) +
106  & (x(2,i) - rdens(2))*xdot(2,i) +
107  & (x(3,i) - rdens(3))*xdot(3,i))/sqrt(ri2)
108  k = 0
109  IF (name(i).LT.0) k = -1
110  gx = gamma(j)*(semi*(1.0 + sqrt(ecc2))/r(j))**3
111  WRITE (18,40) ttot, name(j1), name(j2), list(2,j2), k,
112  & body(j1), body(j2), eb, semi, sqrt(ecc2),
113  & gx, sqrt(ri2), vr
114  40 FORMAT (' T =',f7.1,' NAME = ',2i6,2i3,' M =',2f9.4,
115  & ' EB =',f10.5,' A =',f8.5,' E =',f5.2,
116  & ' GX =',f6.3,' RI =',f6.2,' VR =',f4.1)
117  CALL flush(18)
118  END IF
119 * Reset c.m. Roche flag to standard type for non-zero eccentricity.
120  IF (kstar(i).GE.10.AND.ecc2.GT.4.0d-06) kstar(i) = 0
121  IF (kstar(i).GE.10) k10 = k10 + 1
122  50 CONTINUE
123 *
124 * Set fractional gain of binding energy (initial energy = -0.25).
125  IF (time.LE.0.0d0) THEN
126  jor = nbin0
127  db = 0.0
128  ELSE
129  e(9) = emerge
130  db = -4.0*(e(1) + e(2) + e(5) + e(7) + e(9) + ecoll + emdot
131  & + ekick - ebin0)
132  END IF
133 *
134 * Print eccentricity & energy distributions.
135  IF (npairs.EQ.0) go to 70
136  WRITE (6,60) jor, jex, db, sbcoll, bbcoll, chcoll, jc, nchaos,
137  & newb, k10, (jd(j),j=1,jlast)
138  60 FORMAT (/,' BINARIES',4x,'OR =',i5,' EX =',i3,' DB =',f7.3,
139  & ' SB =',f8.4,' BB =',f8.4,' CH =',f8.4,' NC =',i3,
140  & ' NCH =',i4,' NEWB =',i4,' CIRC =',i4,' N(A) =',10i4)
141 *
142  IF (disp.GT.0.0d0) disp = sqrt(disp/float(npairs))
143  emax = sqrt(emax)
144  WRITE (6,65) disp, emax, (npop(j),j=1,8), (jeb(k),k=1,klast)
145  65 FORMAT (' <E> =',f5.2,' EMAX =',f7.4,' NPOP =',i5,i5,2i6,i4,3i3,
146  & ' EB/KT =',14i4)
147 *
148 * Form the basic internal energy (binaries & single particles).
149  70 etot = 0.0d0
150  e(3) = zkin - pot + etide
151  DO 80 j = 1,3
152  etot = etot + e(j)
153  80 CONTINUE
154 *
155 * Sum all separate energy components to monitor conservation.
156  etot = etot + esub + emerge + emdot + ecdot + ecoll
157 *
158 * Include energy of chain if NCH > 0.
159  IF (nch.GT.0) THEN
160  etot = etot + ech
161  END IF
162 *
163 * Form the net energy gain in binary interactions (also in events.f).
164  degrav = ebin + esub + ebesc + emesc + emerge + egrav - ebin0
165  WRITE (6,90) (e(j),j=1,10), etot, detot, degrav
166  90 FORMAT (' ENERGIES ',10f10.5,' ETOT =',f11.6,' DETOT =',f10.6,
167  & ' DEGRAV =',f7.3)
168 *
169  RETURN
170 *
171  END