14 IF (kz(5).GT.0) go to 20
20 a(k+1) = 2.0*
ran2(kdum) - 1.0
21 a(1) = a(1) + a(k+1)**2
23 IF (a(1).GT.1.0) go to 1
27 a(k+5) = 2.0*
ran2(kdum) - 1.0
28 a(5) = a(5) + a(k+5)**2
30 IF (a(5).GT.1.0) go to 4
51 IF (kz(5).GE.5) go to 52
56 IF (a(1).LT.1.0d-10) go to 30
57 ri = (a(1)**(-0.6666667) - 1.0)**(-0.5)
59 IF (ri.GT.10.0) go to 30
63 x(3,i) = (1.0 - 2.0*a(2))*ri
64 x(1,i) = sqrt(ri**2 - x(3,i)**2)*cos(twopi*a(3))
65 x(2,i) = sqrt(ri**2 - x(3,i)**2)*sin(twopi*a(3))
68 a(6) = a(4)**2*(1.0 - a(4)**2)**3.5
69 IF (0.1*a(5).GT.a(6)) go to 32
71 a(8) = a(4)*sqrt(2.0)/(1.0 + ri**2)**0.25
74 xdot(3,i) = (1.0 - 2.0*a(6))*a(8)
75 xdot(1,i) = sqrt(a(8)**2 - xdot(3,i)**2)*cos(twopi*a(7))
76 xdot(2,i) = sqrt(a(8)**2 - xdot(3,i)**2)*sin(twopi*a(7))
80 cmr(k) = cmr(k) + body(i)*x(k,i)
81 cmrdot(k) = cmrdot(k) + body(i)*xdot(k,i)
90 x(k,i) = x(k,i) - cmr(k)/zmass
91 xdot(k,i) = xdot(k,i) - cmrdot(k)/zmass
93 xdot(k,i) = sv*xdot(k,i)
96 WRITE (10,48) body(i), (x(k,i),k=1,3), (xdot(k,i),k=1,3)
100 IF (kz(22).EQ.1) CALL flush(10)
103 IF (kz(5).LE.1.OR.kz(5).GE.5) go to 200
109 READ (5,*) apo, ecc, n2,
scale
111 semi = apo/(1.0 + ecc)
112 semi = min(semi,50.0d0)
113 semi = max(semi,2.0d0)
114 ecc = min(ecc,0.999d0)
122 fac1 = zm2/(zmass + zm2)
123 fac2 = zmass/(zmass + zm2)
129 vap = sqrt(zmass/semi)*sqrt((1.0 - ecc)/(1.0 + ecc))
135 x(1,i+n) =
scale*x(1,j) + fac2*apo
136 x(2,i+n) =
scale*x(2,j)
137 x(3,i+n) =
scale*x(3,j)
138 xdot(1,i+n) = xdot(1,j)/sqrt(
scale)
139 xdot(2,i+n) = xdot(2,j)/sqrt(
scale) + fac2*vap
140 xdot(3,i+n) = xdot(3,j)/sqrt(
scale)
142 x(1,i) = x(1,i) - fac1*apo
143 xdot(2,i) = xdot(2,i) - fac1*vap
145 ELSE IF (kz(5).EQ.3)
THEN
147 READ (5,*) apo, ecc, dmin,
scale
158 body(i) = 1.0d-03/float(n)
159 semi = rin + (rout - rin)*float(i)/float(n)
160 vcirc = sqrt((body(1) + body(i))/semi)
161 phase = twopi*
ran2(kdum)
162 x(1,i) = semi*cos(phase)
163 x(2,i) = semi*sin(phase)
164 x(3,i) = 0.01*(2.0*
ran2(kdum) - 1.0)
165 xdot(1,i) = -vcirc*sin(phase)
166 xdot(2,i) = vcirc*cos(phase)
167 xdot(3,i) = 0.01*vcirc*(2.0*
ran2(kdum) - 1.0)
175 body(n+1) =
scale*body(1)
177 fac1 = body(n+1)/(zmass + body(n+1))
178 fac2 = zmass/(zmass + body(n+1))
179 zmass = zmass + body(n+1)
181 IF (abs(ecc - 1.0).GT.1.0d-05)
THEN
182 semi = dmin/(1.0 - ecc)
186 vm2 = zmass*(2.0/dmin - 1.0/semi)
187 vap2 = zmass*(2.0/apo - 1.0/semi)
189 vy = sqrt(vm2)*dmin/apo
190 vx = sqrt(vap2 - vy**2)
195 xdot(1,n+1) = -vx*fac2
196 xdot(2,n+1) = vy*fac2
200 x(1,i) = x(1,i) - fac1*apo
201 xdot(1,i) = xdot(1,i) + fac1*vx
202 xdot(2,i) = xdot(2,i) - fac1*vy
204 ELSE IF (kz(5).EQ.4)
THEN
207 READ (5,*) semi, ecc, zm1, zm2
208 WRITE (6,72) semi, ecc, zm1, zm2
209 72
FORMAT (/,12x,
'MASSIVE BODIES A =',1p,e9.1,
210 &
' E =',0p,f6.2,
' M1/<M> =',f6.2,
' M2/<M> =',f6.2)
215 vap = sqrt((zm1 + zm2)/semi)*sqrt((1.0 - ecc)/(1.0 + ecc))
216 fac1 = zm2/(zm1 + zm2)
217 fac2 = zm1/(zm1 + zm2)
224 x(1,1) = -fac1*semi*(1.0 + ecc)
225 x(1,2) = fac2*semi*(1.0 + ecc)
226 xdot(2,1) = -fac1*vap
229 ELSE IF (kz(5).EQ.5)
THEN
231 zmh = 1.0/sqrt(float(2*n))
234 ri = zm*a0/(1.0 - zm)
236 IF (ri.GT.10.0.OR.ri.LT.5.0d-03) go to 80
239 x(3,i) = (1.0 - 2.0*a(2))*ri
240 x(1,i) = sqrt(ri**2 - x(3,i)**2)*cos(twopi*a(3))
241 x(2,i) = sqrt(ri**2 - x(3,i)**2)*sin(twopi*a(3))
242 vi2 = 1.0/(ri + a0) + 2.0*zmh/ri
244 vk2 = vi2*
ran2(kdum)/3.0
245 zz = 2.0*
ran2(kdum) - 1.0
247 IF (zz.LT.0.0) ss = -1.0
248 xdot(k,i) = ss*sqrt(vk2)
252 cmr(k) = cmr(k) + body(i)*x(k,i)
253 cmrdot(k) = cmrdot(k) + body(i)*xdot(k,i)
260 ELSE IF (kz(5).GE.6)
THEN
262 y0 = 5.0*1.25/twopi/sqrt(float(n))
264 rh = (exp(y0) - 1.0d0)**0.4
265 zmh = 4.0*twopi/5.0*log(1.0d0 + rh**2.5)
268 IF (kz(24).LT.0)
THEN
271 y0 = 1.25/twopi*(zmh/float(n))
272 rh = (exp(y0) - 1.0d0)**0.4
277 IF (kz(28).EQ.3)
THEN
278 zmh = 1.0/sqrt(float(2*n))
279 y0 = 1.25/twopi*(zmh/float(n))
280 rh = (exp(y0) - 1.0d0)**0.4
285 cutm = 4.0*twopi/5.0*log(1.0d0 + reject**2.5)
287 zmh = zmh/(float(n)*zmbar)*cutm
289 rh = (exp(y0) - 1.0d0)**0.4
295 zmh = log(1.0d0 + rh**0.75)
297 cutm = log(1.0d0 + reject**0.75)
308 ri = (zy - 1.0d0)**0.4
312 ri = (zy - 1.0d0)**(4.0/3.0)
315 IF (ri.GT.reject.OR.ri.LT.1.0d-04) go to 110
318 x(3,i) = (1.0 - 2.0*a(2))*ri
319 x(1,i) = sqrt(ri**2 - x(3,i)**2)*cos(twopi*a(3))
320 x(2,i) = sqrt(ri**2 - x(3,i)**2)*sin(twopi*a(3))
321 115
IF (kz(5).EQ.6)
THEN
322 CALL
vdisp(ri,r2,zmh,vi2)
324 CALL
vdisp2(ri,r2,zmh,vi2)
330 IF (max(abs(vx),abs(vy),abs(vz)).GT.3.0*sigma) go to 115
334 IF (ri.GT.rcut) go to 120
335 semi = 2.0/ri - (vx**2 + vy**2 + vz**2)/zmh
337 rrdot = x(1,i)*vx + x(2,i)*vy + x(3,i)*vz
338 ecc2 = (1.0 - ri/semi)**2 + rrdot**2/(semi*zmh)
340 IF (semi*(1.0 - ecc).LT.0.5*rcut)
THEN
346 WRITE (6,125) rh, zmh, cutm, rcut, icut
347 125
FORMAT (/,12x,
'BLACK HOLE RH =',f6.3,
' MBH =',f8.4,
348 &
' CUTM =',f7.3,
' RCUT =',f9.5,
' ICUT =',i5)
353 IF (kz(24).LT.0) body(1) = zmh
362 cmr(k) = cmr(k) + body(i)*x(k,i)
363 cmrdot(k) = cmrdot(k) + body(i)*xdot(k,i)
373 IF (n.GE.nmax-10)
THEN
374 WRITE (6,150) n, nmax
375 150
FORMAT (
' DANGER! LIMIT EXCEEDED N =',i6,
' NMAX =',i6)
380 WRITE (6,155) semi, ecc, n1, n2,
scale
381 155
FORMAT (/,12x,
'PLUMMER BINARY A =',f6.2,
' E =',f6.2,
382 &
' N1 =',i6,
' N2 =',i6,
' SCALE =',f6.2)
383 ELSE IF (kz(5).EQ.3)
THEN
384 WRITE (6,160) apo, ecc, dmin,
scale
385 160
FORMAT (/,12x,
'MASSIVE PERTURBER APO =',f6.2,
' E =',f6.2,
386 &
' DMIN =',f6.2,
' MP/M1 =',f6.2)
396 zmass = zmass + body(i)
398 cmr(k) = cmr(k) + body(i)*x(k,i)
399 cmrdot(k) = cmrdot(k) + body(i)*xdot(k,i)
404 x(k,i) = x(k,i) - cmr(k)/zmass
405 xdot(k,i) = xdot(k,i) - cmrdot(k)/zmass
421 common/randg/ gset,iset
425 1 v1=2.*
ran2(idum)-1.
429 fac=sqrt(-2.*log(r)/r)
445 IMPLICIT REAL*8 (a-h,o-z)
450 rho = 1.0/(sqrt(ri)*(1.0 + ri**2*sqrt(ri)))
451 ncall = 1000 + 100.0/ri**2
452 dr = 2.0*(r2 - ri)/float(ncall)
457 CALL
vfunc(zmh,u1,f1)
459 CALL
vfunc(zmh,u2,f2)
461 CALL
vfunc(zmh,u3,f3)
462 sum = sum + one3*(f1 + 4.0d0*f2 + f3)*dr/2.0d0
467 IF (u.GT.100.0) go to 40
476 IMPLICIT REAL*8 (a-h,m,o-z)
479 zmu = 0.8*6.2831853*log(1.0d0 + u2*sqrt(u))
480 rho = 1.0/(sqrt(u)*(1.0 + u2*sqrt(u)))
481 f = rho*(zmu + zmh)/u2
491 IMPLICIT REAL*8 (a-h,o-z)
496 rho = 1.0/(ri**2.25*(1.0 + ri**0.75))
497 ncall = 1000 + 100.0/ri**2
498 dr = 2.0*(r2 - ri)/float(ncall)
508 sum = sum + one3*(f1 + 4.0d0*f2 + f3)*dr/2.0d0
513 IF (u.GT.200.0) go to 40
522 IMPLICIT REAL*8 (a-h,m,o-z)
525 zmu = log(1.0d0 + u**0.75)
526 rho = 1.0/(u**2.25*(1.0 + u**0.75))
527 f = rho*(zmu + zmh)/u2