-
Notifications
You must be signed in to change notification settings - Fork 24
/
close6.for
1786 lines (1741 loc) · 50.4 KB
/
close6.for
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c CLOSE6.FOR (ErikSoft 5 June 2001)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Makes output files containing details of close encounters that occurred
c during an integration using Mercury6 or higher.
c
c The user specifies the names of the required objects in the file close.in
c
c texadactyl_20180507.1 Handle warnings in mio_err() calls about character string lengths
c texadactyl_20180507.2 Handle warnings in mio_spl() calls about argument array bounds too small
c texadactyl_20180507.5 Fix mishandling of infile(j) - needs to be filled out with spaces
c
c------------------------------------------------------------------------------
c
implicit none
include 'mercury.inc'
c
integer itmp,i,j,k,l,iclo,jclo,precision,lenin
integer nmaster,nopen,nwait,nbig,nsml,nsub,lim(2,100)
integer year,month,timestyle,line_num,lenhead,lmem(NMESS)
integer nchar,algor,allflag,firstflag,ninfile
integer unit(NMAX),master_unit(NMAX)
real*8 time,t0,t1,rmax,rcen,rfac,dclo,mcen,jcen(3)
real*8 mio_c2re, mio_c2fl,fr,theta,phi,fv,vtheta,vphi,gm
real*8 x1(3),x2(3),v1(3),v2(3),m(NMAX)
real*8 a1,a2,e1,e2,i1,i2,p1,p2,n1,n2,l1,l2,q1,q2
logical test
character*250 string,fout,header,infile(50)
character*80 mem(NMESS),cc,c(NMAX)
character*25 master_id(NMAX),id(NMAX)
character*5 fin
character*1 check,style,type,c1
c
c------------------------------------------------------------------------------
c
allflag = 0
c
c Read in output messages
inquire (file='message.in', exist=test)
if (.not.test) then
write (*,'(/,2a)') ' ERROR: This file is needed to continue: ',
% ' message.in'
stop
end if
open (14, file='message.in', status='old')
10 continue
read (14,'(i3,1x,i2,1x,a80)',end=20) j,lmem(j),mem(j)
goto 10
20 close (14)
c
c Open file containing parameters for this programme
inquire (file='close.in', exist=test)
if (test) then
open (10, file='close.in', status='old')
else
call mio_err (6,mem(81),lmem(81),mem(88),lmem(88),' ',1,
% 'close.in',9)
end if
c
c Read number of input files
30 read (10,'(a250)') string
if (string(1:1).eq.')') goto 30
call mio_spl (250,string,nsub,lim)
read (string(lim(1,nsub):lim(2,nsub)),*) ninfile
c
c Make sure all the input files exist
do j = 1, ninfile
40 read (10,'(a250)') string
if (string(1:1).eq.')') goto 40
call mio_spl (250,string,nsub,lim)
c texadactyl_20180507.5
c infile(j)(1:(lim(2,1)-lim(1,1)+1)) = string(lim(1,1):lim(2,1))
infile(j)= string(lim(1,1):lim(2,1))
inquire (file=infile(j), exist=test)
if (.not.test) call mio_err (6,mem(81),lmem(81),mem(88),
% lmem(88),' ',1,infile(j),80)
end do
c
c Read parameters used by this programme
timestyle = 1
do j = 1, 2
50 read (10,'(a250)') string
if (string(1:1).eq.')') goto 50
call mio_spl (250,string,nsub,lim)
c1 = string(lim(1,nsub):lim(2,nsub))
if (j.eq.1.and.(c1.eq.'d'.or.c1.eq.'D')) timestyle = 0
if (j.eq.2.and.(c1.eq.'y'.or.c1.eq.'Y')) timestyle = timestyle+2
end do
c
c Read in the names of the objects for which orbital elements are required
nopen = 0
nwait = 0
nmaster = 0
call m_formce (timestyle,fout,header,lenhead)
60 continue
read (10,'(a250)',end=70) string
call mio_spl (250,string,nsub,lim)
if (string(1:1).eq.')'.or.lim(1,1).eq.-1) goto 60
c
c Either open an aei file for this object or put it on the waiting list
nmaster = nmaster + 1
itmp = min(24,lim(2,1)-lim(1,1))
master_id(nmaster)=' '
master_id(nmaster)(1:itmp+1) = string(lim(1,1):lim(1,1)+itmp)
if (nopen.lt.NFILES) then
nopen = nopen + 1
master_unit(nmaster) = 10 + nopen
call mio_aei (master_id(nmaster),'.clo',master_unit(nmaster),
% header,lenhead,mem,lmem)
else
nwait = nwait + 1
master_unit(nmaster) = -2
end if
goto 60
c
70 continue
c If no objects are listed in CLOSE.IN assume that all objects are required
if (nopen.eq.0) allflag = 1
close (10)
c
c------------------------------------------------------------------------------
c
c LOOP OVER EACH INPUT FILE CONTAINING INTEGRATION DATA
c
90 continue
firstflag = 0
do i = 1, ninfile
line_num = 0
open (10, file=infile(i), status='old')
c
c Loop over each time slice
100 continue
line_num = line_num + 1
read (10,'(3a1)',end=900,err=666) check,style,type
line_num = line_num - 1
backspace 10
c
c Check if this is an old style input file
if (ichar(check).eq.12.and.(style.eq.'0'.or.style.eq.'1'.or.
% style.eq.'2'.or.style.eq.'3'.or.style.eq.'4')) then
write (*,'(/,2a)') ' ERROR: This is an old style data file',
% ' Try running m_close5.for instead.'
stop
end if
if (ichar(check).ne.12) goto 666
c
c------------------------------------------------------------------------------
c
c IF SPECIAL INPUT, READ TIME, PARAMETERS, NAMES, MASSES ETC.
c
if (type.eq.'a') then
line_num = line_num + 1
read (10,'(3x,i2,a62,i1)') algor,cc(1:62),precision
c
c Decompress the time, number of objects, central mass and J components etc.
time = mio_c2fl (cc(1:8))
if (firstflag.eq.0) then
t0 = time
firstflag = 1
end if
nbig = int(.5d0 + mio_c2re(cc(9:16), 0.d0, 11239424.d0, 3))
nsml = int(.5d0 + mio_c2re(cc(12:19),0.d0, 11239424.d0, 3))
mcen = mio_c2fl (cc(15:22)) * K2
jcen(1) = mio_c2fl (cc(23:30))
jcen(2) = mio_c2fl (cc(31:38))
jcen(3) = mio_c2fl (cc(39:46))
rcen = mio_c2fl (cc(47:54))
rmax = mio_c2fl (cc(55:62))
rfac = log10 (rmax / rcen)
c
c Read in strings containing compressed data for each object
do j = 1, nbig + nsml
line_num = line_num + 1
read (10,'(a)',err=666) c(j)(1:68)
end do
c
c Create input format list
if (precision.eq.1) nchar = 2
if (precision.eq.2) nchar = 4
if (precision.eq.3) nchar = 7
lenin = 3 + 6 * nchar
fin(1:5) = '(a00)'
write (fin(3:4),'(i2)') lenin
c
c For each object decompress its name, code number, mass, spin and density
do j = 1, nbig + nsml
k = int(.5d0 + mio_c2re(c(j)(1:8),0.d0,11239424.d0,3))
id(k) = c(j)(4:28)
m(k) = mio_c2fl (c(j)(29:36)) * K2
c
c Find the object on the master list
unit(k) = 0
do l = 1, nmaster
if (id(k).eq.master_id(l)) unit(k) = master_unit(l)
end do
c
c If object is not on the master list, add it to the list now
if (unit(k).eq.0) then
nmaster = nmaster + 1
master_id(nmaster) = id(k)
c
c Either open an aei file for this object or put it on the waiting list
if (allflag.eq.1) then
if (nopen.lt.NFILES) then
nopen = nopen + 1
master_unit(nmaster) = 10 + nopen
call mio_aei (master_id(nmaster),'.clo',
% master_unit(nmaster),header,lenhead,mem,lmem)
else
nwait = nwait + 1
master_unit(nmaster) = -2
end if
else
master_unit(nmaster) = -1
end if
unit(k) = master_unit(nmaster)
end if
end do
c
c------------------------------------------------------------------------------
c
c IF NORMAL INPUT, READ COMPRESSED DATA ON THE CLOSE ENCOUNTER
c
else if (type.eq.'b') then
line_num = line_num + 1
read (10,'(3x,a70)',err=666) cc(1:70)
c
c Decompress time, distance and orbital variables for each object
time = mio_c2fl (cc(1:8))
iclo = int(.5d0 + mio_c2re(cc(9:16), 0.d0, 11239424.d0, 3))
jclo = int(.5d0 + mio_c2re(cc(12:19), 0.d0, 11239424.d0, 3))
if (iclo.gt.NMAX.or.jclo.gt.NMAX) then
write (*,'(/,2a)') mem(81)(1:lmem(81)),
% mem(90)(1:lmem(90))
stop
end if
dclo = mio_c2fl (cc(15:22))
fr = mio_c2re (cc(23:30), 0.d0, rfac, 4)
theta = mio_c2re (cc(27:34), 0.d0, PI, 4)
phi = mio_c2re (cc(31:38), 0.d0, TWOPI, 4)
fv = mio_c2re (cc(35:42), 0.d0, 1.d0, 4)
vtheta = mio_c2re (cc(39:46), 0.d0, PI, 4)
vphi = mio_c2re (cc(43:50), 0.d0, TWOPI, 4)
call mco_ov2x (rcen,rmax,mcen,m(iclo),fr,theta,phi,fv,
% vtheta,vphi,x1(1),x1(2),x1(3),v1(1),v1(2),v1(3))
c
fr = mio_c2re (cc(47:54), 0.d0, rfac, 4)
theta = mio_c2re (cc(51:58), 0.d0, PI, 4)
phi = mio_c2re (cc(55:62), 0.d0, TWOPI, 4)
fv = mio_c2re (cc(59:66), 0.d0, 1.d0, 4)
vtheta = mio_c2re (cc(63:70), 0.d0, PI, 4)
vphi = mio_c2re (cc(67:74), 0.d0, TWOPI, 4)
call mco_ov2x (rcen,rmax,mcen,m(jclo),fr,theta,phi,fv,
% vtheta,vphi,x2(1),x2(2),x2(3),v2(1),v2(2),v2(3))
c
c Convert to Keplerian elements
gm = mcen + m(iclo)
call mco_x2el (gm,x1(1),x1(2),x1(3),v1(1),v1(2),v1(3),
% q1,e1,i1,p1,n1,l1)
a1 = q1 / (1.d0 - e1)
gm = mcen + m(jclo)
call mco_x2el (gm,x2(1),x2(2),x2(3),v2(1),v2(2),v2(3),
% q2,e2,i2,p2,n2,l2)
a2 = q2 / (1.d0 - e2)
i1 = i1 / DR
i2 = i2 / DR
c
c Convert time to desired format
if (timestyle.eq.0) t1 = time
if (timestyle.eq.1) call mio_jd_y (time,year,month,t1)
if (timestyle.eq.2) t1 = time - t0
if (timestyle.eq.3) t1 = (time - t0) / 365.25d0
c
c Write encounter details to appropriate files
if (timestyle.eq.1) then
if (unit(iclo).ge.10) write (unit(iclo),fout) year,month,
% t1,id(jclo),dclo,a1,e1,i1,a2,e2,i2
c
if (unit(jclo).ge.10) write (unit(jclo),fout) year,month,
% t1,id(iclo),dclo,a2,e2,i2,a1,e1,i1
else
if (unit(iclo).ge.10) write (unit(iclo),fout) t1,id(jclo),
% dclo,a1,e1,i1,a2,e2,i2
if (unit(jclo).ge.10) write (unit(jclo),fout) t1,id(iclo),
% dclo,a2,e2,i2,a1,e1,i1
end if
c
c------------------------------------------------------------------------------
c
c IF TYPE IS NOT 'a' OR 'b', THE INPUT FILE IS CORRUPTED
c
else
goto 666
end if
c
c Move on to the next time slice
goto 100
c
c If input file is corrupted, try to continue from next uncorrupted time slice
666 continue
write (*,'(2a,/,a,i10)') mem(121)(1:lmem(121)),
% infile(i)(1:60),mem(104)(1:lmem(104)),line_num
c1 = ' '
do while (ichar(c1).ne.12)
line_num = line_num + 1
read (10,'(a1)',end=900) c1
end do
line_num = line_num - 1
backspace 10
c
c Move on to the next file containing close encounter data
900 continue
close (10)
end do
c
c Close clo files
do j = 1, nopen
close (10+j)
end do
nopen = 0
c
c If some objects remain on waiting list, read through input files again
if (nwait.gt.0) then
do j = 1, nmaster
if (master_unit(j).ge.10) master_unit(j) = -1
if (master_unit(j).eq.-2.and.nopen.lt.NFILES) then
nopen = nopen + 1
nwait = nwait - 1
master_unit(j) = 10 + nopen
call mio_aei (master_id(j),'.clo',master_unit(j),header,
% lenhead,mem,lmem)
end if
end do
goto 90
end if
c
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c M_FORMCE.FOR (ErikSoft 30 November 1999)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c
c------------------------------------------------------------------------------
c
subroutine m_formce (timestyle,fout,header,lenhead)
c
implicit none
c
c Input/Output
integer timestyle,lenhead
character*250 fout,header
c
c------------------------------------------------------------------------------
c
if (timestyle.eq.0.or.timestyle.eq.2) then
header(1:19) = ' Time (days) '
header(20:65) = ' Object dmin (AU) a1 '
header(66:108) = ' e1 i1 a2 e2 i2'
lenhead = 107
fout = '(1x,f18.5,1x,a25,1x,f10.8,2(1x,f9.4,1x,f8.6,1x,f7.3))'
else
if (timestyle.eq.1) then
header(1:23) = ' Year/Month/Day '
header(24:67) = ' Object dmin (AU) a1'
header(68:112)=' e1 i1 a2 e2 i2'
lenhead = 111
fout(1:38) = '(1x,i10,1x,i2,1x,f8.5,1x,a25,1x,f10.8,'
fout(39:65) = '2(1x,f9.4,1x,f8.6,1x,f7.3))'
else
header(1:19) = ' Time (years) '
header(20:63) = ' Object dmin (AU) a1'
header(64:107) =' e1 i1 a2 e2 i2'
fout = '(1x,f18.7,1x,a25,1x,f10.8,2(1x,f9.4,1x,f8.6,1x,f7.3))'
lenhead = 107
end if
end if
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_OV2X.FOR (ErikSoft 28 February 2001)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Converts output variables for an object to coordinates and velocities.
c The output variables are:
c r = the radial distance
c theta = polar angle
c phi = azimuthal angle
c fv = 1 / [1 + 2(ke/be)^2], where be and ke are the object's binding and
c kinetic energies. (Note that 0 < fv < 1).
c vtheta = polar angle of velocity vector
c vphi = azimuthal angle of the velocity vector
c
c------------------------------------------------------------------------------
c
subroutine mco_ov2x (rcen,rmax,mcen,m,fr,theta,phi,fv,vtheta,
% vphi,x,y,z,u,v,w)
c
implicit none
include 'mercury.inc'
c
c Input/Output
real*8 rcen,rmax,mcen,m,x,y,z,u,v,w,fr,theta,phi,fv,vtheta,vphi
c
c Local
real*8 r,v1,temp
c
c------------------------------------------------------------------------------
c
r = rcen * 10.d0**fr
temp = sqrt(.5d0*(1.d0/fv - 1.d0))
v1 = sqrt(2.d0 * temp * (mcen + m) / r)
c
x = r * sin(theta) * cos(phi)
y = r * sin(theta) * sin(phi)
z = r * cos(theta)
u = v1 * sin(vtheta) * cos(vphi)
v = v1 * sin(vtheta) * sin(vphi)
w = v1 * cos(vtheta)
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_EL2X.FOR (ErikSoft 7 July 1999)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Calculates Cartesian coordinates and velocities given Keplerian orbital
c elements (for elliptical, parabolic or hyperbolic orbits).
c
c Based on a routine from Levison and Duncan's SWIFT integrator.
c
c mu = grav const * (central + secondary mass)
c q = perihelion distance
c e = eccentricity
c i = inclination )
c p = longitude of perihelion !!! ) in
c n = longitude of ascending node ) radians
c l = mean anomaly )
c
c x,y,z = Cartesian positions ( units the same as a )
c u,v,w = " velocities ( units the same as sqrt(mu/a) )
c
c------------------------------------------------------------------------------
c
subroutine mco_el2x (mu,q,e,i,p,n,l,x,y,z,u,v,w)
c
implicit none
include 'mercury.inc'
c
c Input/Output
real*8 mu,q,e,i,p,n,l,x,y,z,u,v,w
c
c Local
real*8 g,a,ci,si,cn,sn,cg,sg,ce,se,romes,temp
real*8 z1,z2,z3,z4,d11,d12,d13,d21,d22,d23
real*8 mco_kep, orbel_fhybrid, orbel_zget
c
c------------------------------------------------------------------------------
c
c Change from longitude of perihelion to argument of perihelion
g = p - n
c
c Rotation factors
call mco_sine (i,si,ci)
call mco_sine (g,sg,cg)
call mco_sine (n,sn,cn)
z1 = cg * cn
z2 = cg * sn
z3 = sg * cn
z4 = sg * sn
d11 = z1 - z4*ci
d12 = z2 + z3*ci
d13 = sg * si
d21 = -z3 - z2*ci
d22 = -z4 + z1*ci
d23 = cg * si
c
c Semi-major axis
a = q / (1.d0 - e)
c
c Ellipse
if (e.lt.1.d0) then
romes = sqrt(1.d0 - e*e)
temp = mco_kep (e,l)
call mco_sine (temp,se,ce)
z1 = a * (ce - e)
z2 = a * romes * se
temp = sqrt(mu/a) / (1.d0 - e*ce)
z3 = -se * temp
z4 = romes * ce * temp
else
c Parabola
if (e.eq.1.d0) then
ce = orbel_zget(l)
z1 = q * (1.d0 - ce*ce)
z2 = 2.d0 * q * ce
z4 = sqrt(2.d0*mu/q) / (1.d0 + ce*ce)
z3 = -ce * z4
else
c Hyperbola
romes = sqrt(e*e - 1.d0)
temp = orbel_fhybrid(e,l)
call mco_sinh (temp,se,ce)
z1 = a * (ce - e)
z2 = -a * romes * se
temp = sqrt(mu/abs(a)) / (e*ce - 1.d0)
z3 = -se * temp
z4 = romes * ce * temp
end if
endif
c
x = d11*z1 + d21*z2
y = d12*z1 + d22*z2
z = d13*z1 + d23*z2
u = d11*z3 + d21*z4
v = d12*z3 + d22*z4
w = d13*z3 + d23*z4
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_KEP.FOR (ErikSoft 7 July 1999)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Solves Kepler's equation for eccentricities less than one.
c Algorithm from A. Nijenhuis (1991) Cel. Mech. Dyn. Astron. 51, 319-330.
c
c e = eccentricity
c l = mean anomaly (radians)
c u = eccentric anomaly ( " )
c
c------------------------------------------------------------------------------
c
function mco_kep (e,oldl)
implicit none
c
c Input/Outout
real*8 oldl,e,mco_kep
c
c Local
real*8 l,pi,twopi,piby2,u1,u2,ome,sign
real*8 x,x2,sn,dsn,z1,z2,z3,f0,f1,f2,f3
real*8 p,q,p2,ss,cc
logical flag,big,bigg
c
c------------------------------------------------------------------------------
c
pi = 3.141592653589793d0
twopi = 2.d0 * pi
piby2 = .5d0 * pi
c
c Reduce mean anomaly to lie in the range 0 < l < pi
if (oldl.ge.0d0) then
l = mod(oldl, twopi)
else
l = mod(oldl, twopi) + twopi
end if
sign = 1.d0
if (l.gt.pi) then
l = twopi - l
sign = -1.d0
end if
c
ome = 1.d0 - e
c
if (l.ge..45d0.or.e.lt..55d0) then
c
c Regions A,B or C in Nijenhuis
c -----------------------------
c
c Rough starting value for eccentric anomaly
if (l.lt.ome) then
u1 = ome
else
if (l.gt.(pi-1.d0-e)) then
u1 = (l+e*pi)/(1.d0+e)
else
u1 = l + e
end if
end if
c
c Improved value using Halley's method
flag = u1.gt.piby2
if (flag) then
x = pi - u1
else
x = u1
end if
x2 = x*x
sn = x*(1.d0 + x2*(-.16605d0 + x2*.00761d0) )
dsn = 1.d0 + x2*(-.49815d0 + x2*.03805d0)
if (flag) dsn = -dsn
f2 = e*sn
f0 = u1 - f2 - l
f1 = 1.d0 - e*dsn
u2 = u1 - f0/(f1 - .5d0*f0*f2/f1)
else
c
c Region D in Nijenhuis
c ---------------------
c
c Rough starting value for eccentric anomaly
z1 = 4.d0*e + .5d0
p = ome / z1
q = .5d0 * l / z1
p2 = p*p
z2 = exp( log( dsqrt( p2*p + q*q ) + q )/1.5d0 )
u1 = 2.d0*q / ( z2 + p + p2/z2 )
c
c Improved value using Newton's method
z2 = u1*u1
z3 = z2*z2
u2 = u1 - .075d0*u1*z3 / (ome + z1*z2 + .375d0*z3)
u2 = l + e*u2*( 3.d0 - 4.d0*u2*u2 )
end if
c
c Accurate value using 3rd-order version of Newton's method
c N.B. Keep cos(u2) rather than sqrt( 1-sin^2(u2) ) to maintain accuracy!
c
c First get accurate values for u2 - sin(u2) and 1 - cos(u2)
bigg = (u2.gt.piby2)
if (bigg) then
z3 = pi - u2
else
z3 = u2
end if
c
big = (z3.gt.(.5d0*piby2))
if (big) then
x = piby2 - z3
else
x = z3
end if
c
x2 = x*x
ss = 1.d0
cc = 1.d0
c----------------------------------------------------------------
ss = x*x2/6.d0*(1.d0 - x2/20.d0*(1.d0 - x2/42.d0*(1.d0 -
% x2/72.d0*(1.d0 - x2/110.d0*(1.d0 - x2/156.d0*(1.d0 -
% x2/210.d0*(1.d0 - x2/272.d0)))))))
cc = x2/2.d0*(1.d0 - x2/12.d0*(1.d0 - x2/30.d0*(1.d0 -
% x2/56.d0*(1.d0 - x2/ 90.d0*(1.d0 - x2/132.d0*(1.d0 -
% x2/182.d0*(1.d0 - x2/240.d0*(1.d0 - x2/306.d0))))))))
c
if (big) then
z1 = cc + z3 - 1.d0
z2 = ss + z3 + 1.d0 - piby2
else
z1 = ss
z2 = cc
end if
c
if (bigg) then
z1 = 2.d0*u2 + z1 - pi
z2 = 2.d0 - z2
end if
c
f0 = l - u2*ome - e*z1
f1 = ome + e*z2
f2 = .5d0*e*(u2-z1)
f3 = e/6.d0*(1.d0-z2)
z1 = f0/f1
z2 = f0/(f2*z1+f1)
mco_kep = sign*( u2 + f0/((f3*z1+f2)*z2+f1) )
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_SINE.FOR (ErikSoft 17 April 1997)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Calculates sin and cos of an angle X (in radians).
c
c------------------------------------------------------------------------------
c
subroutine mco_sine (x,sx,cx)
c
implicit none
c
c Input/Output
real*8 x,sx,cx
c
c Local
real*8 pi,twopi
c
c------------------------------------------------------------------------------
c
pi = 3.141592653589793d0
twopi = 2.d0 * pi
c
if (x.gt.0d0) then
x = mod(x,twopi)
else
x = mod(x,twopi) + twopi
end if
c
cx = cos(x)
c
if (x.gt.pi) then
sx = -sqrt(1.d0 - cx*cx)
else
sx = sqrt(1.d0 - cx*cx)
end if
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_SINH.FOR (ErikSoft 12 June 1998)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Calculates sinh and cosh of an angle X (in radians)
c
c------------------------------------------------------------------------------
c
subroutine mco_sinh (x,sx,cx)
c
implicit none
c
c Input/Output
real*8 x,sx,cx
c
c------------------------------------------------------------------------------
c
sx = sinh(x)
cx = sqrt (1.d0 + sx*sx)
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MIO_AEI.FOR (ErikSoft 31 January 2001)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Creates a filename and opens a file to store aei information for an object.
c The filename is based on the name of the object.
c
c------------------------------------------------------------------------------
c
subroutine mio_aei (id,extn,unitnum,header,lenhead,mem,lmem)
c
implicit none
include 'mercury.inc'
c
c Input/Output
integer unitnum,lenhead,lmem(NMESS)
character*4 extn
character*25 id
character*250 header
character*80 mem(NMESS)
c
c Local
c texadactyl_20180507.2
c integer j,k,itmp,nsub,lim(2,4)
integer j,k,itmp,nsub,lim(2,100)
logical test
character*1 bad(5)
character*250 filename
c
c------------------------------------------------------------------------------
c
data bad/ '*', '/', '.', ':', '&'/
c
c Create a filename based on the object's name
call mio_spl (25,id,nsub,lim)
itmp = min(24,lim(2,1)-lim(1,1))
filename(1:itmp+1) = id(1:itmp+1)
filename(itmp+2:itmp+5) = extn
do j = itmp + 6, 250
filename(j:j) = ' '
end do
c
c Check for inappropriate characters in the filename
do j = 1, itmp + 1
do k = 1, 5
if (filename(j:j).eq.bad(k)) filename(j:j) = '_'
end do
end do
c
c If the file exists already, give a warning and don't overwrite it
inquire (file=filename, exist=test)
if (test) then
write (*,'(/,3a)') mem(121)(1:lmem(121)),mem(87)(1:lmem(87)),
% filename(1:80)
unitnum = -1
else
open (unitnum, file=filename, status='new')
write (unitnum, '(/,30x,a25,//,a)') id,header(1:lenhead)
end if
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MIO_C2FL.FOR (ErikSoft 5 June 2001)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c CHARACTER*8 ASCII string into a REAL*8 variable.
c
c N.B. X will lie in the range -1.e112 < X < 1.e112
c ===
c
c------------------------------------------------------------------------------
c
function mio_c2fl (c)
c
implicit none
c
c Input/Output
real*8 mio_c2fl
character*8 c
c
c Local
real*8 x,mio_c2re
integer ex
c
c------------------------------------------------------------------------------
c
x = mio_c2re (c(1:8), 0.d0, 1.d0, 7)
x = x * 2.d0 - 1.d0
ex = mod(ichar(c(8:8)) + 256, 256) - 32 - 112
mio_c2fl = x * (10.d0**dble(ex))
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MIO_C2RE.FOR (ErikSoft 5 June 2001)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Converts an ASCII string into a REAL*8 variable X, where XMIN <= X < XMAX,
c using the new format compression:
c
c X is assumed to be made up of NCHAR base-224 digits, each one represented
c by a character in the ASCII string. Each digit is given by the ASCII
c number of the character minus 32.
c The first 32 ASCII characters (CTRL characters) are avoided, because they
c cause problems when using some operating systems.
c
c------------------------------------------------------------------------------
c
function mio_c2re (c,xmin,xmax,nchar)
c
implicit none
c
c Input/output
integer nchar
real*8 xmin,xmax,mio_c2re
character*8 c
c
c Local
integer j
real*8 y
c
c------------------------------------------------------------------------------
c
y = 0
do j = nchar, 1, -1
y = (y + dble(mod(ichar(c(j:j)) + 256, 256) - 32)) / 224.d0
end do
c
mio_c2re = xmin + y * (xmax - xmin)
c
c------------------------------------------------------------------------------
c
return
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MIO_ERR.FOR (ErikSoft 6 December 1999)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Writes out an error message and terminates Mercury.
c
c------------------------------------------------------------------------------
c
subroutine mio_err (unit,s1,ls1,s2,ls2,s3,ls3,s4,ls4)
c
implicit none
c
c Input/Output
integer unit,ls1,ls2,ls3,ls4
c texadactyl_20180507.1
c character*80 s1,s2,s3,s4
CHARACTER*(*) s1,s2,s3,s4
c
c------------------------------------------------------------------------------
c
write (*,'(a)') ' ERROR: Programme terminated.'
write (unit,'(/,3a,/,2a)') s1(1:ls1),s2(1:ls2),s3(1:ls3),
% ' ',s4(1:ls4)
stop
c
c------------------------------------------------------------------------------
c
end
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c MCO_H2B.FOR (ErikSoft 2 November 2000)
c
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c
c Author: John E. Chambers
c
c Converts coordinates with respect to the central body to barycentric
c coordinates.
c
c------------------------------------------------------------------------------
c
subroutine mco_h2b (jcen,nbod,nbig,h,m,xh,vh,x,v)
c
implicit none
c
c Input/Output
integer nbod,nbig
real*8 jcen(3),h,m(nbod),xh(3,nbod),vh(3,nbod),x(3,nbod),v(3,nbod)
c
c Local
integer j
real*8 mtot,temp
c
c------------------------------------------------------------------------------
c
mtot = 0.d0
x(1,1) = 0.d0
x(2,1) = 0.d0
x(3,1) = 0.d0
v(1,1) = 0.d0
v(2,1) = 0.d0
v(3,1) = 0.d0
c
c Calculate coordinates and velocities of the central body
do j = 2, nbod
mtot = mtot + m(j)
x(1,1) = x(1,1) + m(j) * xh(1,j)
x(2,1) = x(2,1) + m(j) * xh(2,j)