forked from compxco/genray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbessel.f
3040 lines (3016 loc) · 109 KB
/
bessel.f
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 Following is from the brambilla LH and FW code
ctk--calculation of Bessel function with a complex argument (x,y)
c br(nb),bi(nb)
c y=0,ize=0 >J_0(x)=br(1),J_1(x)=br(2)
c y=0,ize=1 >I_0(x)=br(1),I_1(x)=br(2),... ,I_n(x)=br(n+1),
c n=0,1,2,...; nb.ge.1
C x,y,br,bi - real
subroutine beslci(x,y,nb,ize,br,bi,ncalc)
c
c***** ***** ***** ***** ***** ***** *****
c
c journal of research national bureau of standards
c b-mathematical sciences vol.77-b nos.3-4 july-dec. 1973 p118
c routine to calculate bessel functions j and i
c of complex argument and integer order
c input variables
c x real part of complex argument
c y imaginary part of complex argument
c nb a positive integer designating highest order to be calculated
c ize zero for j*s one for i*s
c br for normal exit,br contains real part of solution vector
c bi for normal exit,bi contains imaginary part of solution vector
c normal exit if ncalc=nb
c br-bi-ncalc need not be initialized
c machine dependent constants
c nsig decimal significance desired. set to ifix(alog10(2)*nbit+1)
c nbit number of bits in the mantissa
c the relative truncation error is limited to t=.5*10**-nsig for
c order greater than abs(z).
c for order less than abs(z) (general test),the relative error is
c limited to t for function values of magnitude at least 1.
c the absolute error is limited to t for smaller values.
c nten largest integer k such that 10**k is machine representable.
c largez upper limit on the magnitude of z. if abs(z)=n, at least
c n iterations of the backward recursion will be executed.
c exparg largest argument that the library exp routine can handle.
c error returns
c let g denote either i or j.
c in case of an error, ncalc.ne.nb and not all g*s are calculated
c to the desired accuracy.
c if ncalc.lt.0, an argument is out of range. nb.le.0 or ize is
c neither 0 nor 1 or ize=0 and abs(y).gt.exparg, or ize=1 and
c abs(x).gt.exparg. in this case,the vectors br and bi are not
c calculated, and ncalc is set to min0(nb,0)-1 so ncalc.ne.nb.
c nb.gt.ncalc.gt.0 will occur if nb.gt.magz and abs(g-sub-nb-of-z/g
c -sub-magx-of-z).lt.10.**(nten/2), i.e. nb is much greater than
c magz. in this case, br(n) and bi(n) are calculated to the desired
c accuracy for n.le.ncalc, but for ncalc.lt.n.le.nb, precision is
c lost. if n.gt.ncalc and abs(g(ncalc-1)/g(n-1)).eq.10**-k, then
c the last k significant figures of g(n-1) (=br(n)+i*bi(n)) are
c erroneous. if the user wishes to calculate g(n-1) to higher
c accuracy, he should use an asymptotic formula for large order.
c
c***** ***** ***** ***** ***** ***** *****
c
dimension br(*),bi(*)
c data nsig,nten,largez,exparg/15,307,10000,700./
data nsig,nten,largez,exparg/15,38,10000,81./
tempar=sqrt(x*x+y*y)
magz=ifix(tempar)
if(nb.gt.0.and.magz.le.largez.and.((ize.eq.0.and.abs(y).le.exparg)
c.or.(ize.eq.1.and.abs(x).le.exparg))) go to 1
c error return z,nb,or ize is out of range
ncalc=min0(nb,0)-1
return
1 sign1=1-2*ize
ncalc=nb
c use 2-term ascending series for small z
if(tempar**4.lt.0.1**nsig) go to 50
c initialize the calculation of the p*s
nbmz=nb-magz
n=magz+1
if(abs(x).lt.abs(y)) go to 2
zinvr=1.0/(x+y*y/x)
zinvi=-y*zinvr/x
go to 3
2 zinvi=-1.0/(y+x*x/y)
zinvr=-x*zinvi/y
3 plastr=1.0
plasti=0.0
pr=sign1*(n+n)*zinvr
pi=sign1*(n+n)*zinvi
test=2.0*(10.0)**nsig
m=0
if(nbmz.lt.3) go to 6
c calculate p*s until n=nb-1. check for possible overflow.
tover=10.0**(nten-nsig)
nstart=magz+2
nend=nb-1
do 5 n=nstart,nend
poldr=plastr
poldi=plasti
plastr=pr
plasti=pi
pr=sign1*((n+n)*(plastr*zinvr-plasti*zinvi)-poldr)
pi=sign1*((n+n)*(plasti*zinvr+plastr*zinvi)-poldi)
if((pr/tover)**2+(pi/tover)**2-1.0) 5,5,7
5 continue
n=nend
c calculate special significance test for nbmz.gt.2.
tempbi=amax1(abs(pr),abs(pi))
tempbi=tempbi*sqrt(2.0*(10.0)**nsig*sqrt(((pr/tempbi)**2+(pi
c/tempbi)**2)*((plastr/tempbi)**2+(plasti/tempbi)**2)))
test=amax1(test,tempbi)
c calculate p*s until significance test is passed
6 n=n+1
poldr=plastr
poldi=plasti
plastr=pr
plasti=pi
pr=sign1*((n+n)*(plastr*zinvr-plasti*zinvi)-poldr)
pi=sign1*((n+n)*(plasti*zinvr+plastr*zinvi)-poldi)
if((pr/test)**2+(pi/test)**2.lt.1.0) go to 6
if(m.eq.1) go to 12
c calculate strict variant of significance test,and
c calculate p*s until this test is passed.
m=1
tempbi=amax1(abs(pr),abs(pi))
tempbr=sqrt(((pr/tempbi)**2+(pi/tempbi)**2)/
c((plastr/tempbi)**2+(plasti/tempbi)**2))
tempbi=(n+1)/tempar
if(tempbr+1.0/tempbr.gt.2.0*tempbi) tempbr=tempbi+sqrt(tempbi**2
c-1.0)
test=test/sqrt(tempbr-1.0/tempbr)
if((pr/test)**2+(pi/test)**2-1.0) 6,12,12
7 nstart=n+1
c to avoid overflow, normalize p*s by dividing by tover.
c calculate p*s until unnormalized p would overflow.
pr=pr/tover
pi=pi/tover
plastr=plastr/tover
plasti=plasti/tover
psaver=pr
psavei=pi
tempcr=plastr
tempci=plasti
test=10.0**(2*nsig)
8 n=n+1
poldr=plastr
poldi=plasti
plastr=pr
plasti=pi
pr=sign1*((n+n)*(plastr*zinvr-plasti*zinvi)-poldr)
pi=sign1*((n+n)*(plasti*zinvr+plastr*zinvi)-poldi)
if(pr**2+pi**2.le.test) go to 8
c calculate backward test,and find ncalc,the highest n
c such that the test is passed.
tempbr=sqrt((plastr**2+plasti**2)/(poldr**2+poldi**2))
tempbi=n/tempar
if(tempbr+1.0/tempbr.gt.2.0*tempbi) tempbr=tempbi+sqrt(tempbi**2
c-1.0)
test=0.5*(1.0-1.0/tempbr**2)/10.0**nsig
test=((plastr**2+plasti**2)*test)*((poldr**2+poldi**2)*test)
pr=plastr*tover
pi=plasti*tover
n=n-1
nend=min0(nb,n)
do 9 ncalc=nstart,nend
poldr=tempcr
poldi=tempci
tempcr=psaver
tempci=psavei
psaver=sign1*((n+n)*(tempcr*zinvr-tempci*zinvi)-poldr)
psavei=sign1*((n+n)*(tempci*zinvr+tempcr*zinvi)-poldi)
if((psaver**2+psavei**2)*(tempcr**2+tempci**2)-test) 9,9,10
9 continue
ncalc=nend+1
10 ncalc=ncalc-1
c the coefficient of b(n) in the normalized sum is
c m*sqrt(-1)**imag,where m=-2,0,or2,and imag is 0 or 1.
c calculate recursion rules for m and imag,and initialize them.
12 n=n+1
tempbr=ize*x+(1-ize)*y
ipos=0
if(tempbr) 13,14,13
13 ipos=ifix(1.1*tempbr/abs(tempbr))
14 mrecur=4*((2+ize+ipos)/2)-3-2*(ize+ipos)
k=2+ipos+2*ize*ipos**2-ize
l=n-4*(n/4)
mlast=2+8*((k*l)/4)-4*((k*l)/2)
if(ipos.eq.0.and.(l.eq.1.or.l.eq.3)) mlast=0
l=l+3-4*((l+3)/4)
m=2+8*((k*l)/4)-4*((k*l)/2)
if(ipos.eq.0.and.(l.eq.1.or.l.eq.3)) m=0
imrecr=(1-ize)*ipos**2
imag=imrecr*(l-2*(l/2))
c initialize the backward recursion and the normalization sum
tempbr=0.0
tempbi=0.0
if(abs(pi).gt.abs(pr)) go to 15
tempar=1.0/(pr+pi*(pi/pr))
tempai=-(pi*tempar)/pr
go to 16
15 tempai=-1.0/(pi+pr*(pr/pi))
tempar=-(pr*tempai)/pi
16 if(imag.ne.0) go to 17
sumr=m*tempar
sumi=m*tempai
go to 18
17 sumr=-m*tempai
sumi=m*tempar
18 nend=n-nb
if(nend) 26,22,19
c recur backward via difference equation calculating (but not
c storing) br(n) and bi(n) until n=nb
19 do 21 l=1,nend
n=n-1
tempcr=tempbr
tempci=tempbi
tempbr=tempar
tempbi=tempai
pr=(n+n)*zinvr
pi=(n+n)*zinvi
tempar=pr*tempbr-pi*tempbi-sign1*tempcr
tempai=pr*tempbi+pi*tempbr-sign1*tempci
imag=(1-imag)*imrecr
k=mlast
mlast=m
m=k*mrecur
if(imag.ne.0) go to 20
sumr=sumr+m*tempar
sumi=sumi+m*tempai
go to 21
20 sumr=sumr-m*tempai
sumi=sumi+m*tempar
21 continue
c store br(nb),bi(nb)
22 br(n)=tempar
bi(n)=tempai
if(n.gt.1) go to 23
c nb=1. since 2*tempar and 2*tempai were added to sumr and sumi
c respectively,we must subaxis(i)ract tempar and tempai
sumr=sumr-tempar
sumi=sumi-tempai
go to 35
c calculate and store br(nb-1),bi(nb-1)
23 n=n-1
pr=(n+n)*zinvr
pi=(n+n)*zinvi
br(n)=pr*tempar-pi*tempai-sign1*tempbr
bi(n)=pr*tempai+pi*tempar-sign1*tempbi
if(n.eq.1) go to 34
imag=(1-imag)*imrecr
k=mlast
mlast=m
m=k*mrecur
if(imag.ne.0) go to 24
sumr=sumr+m*br(n)
sumi=sumi+m*bi(n)
go to 30
24 sumr=sumr-m*bi(n)
sumi=sumi+m*br(n)
go to 30
c n.lt.nb,so store br(n),bi(n) and set higher orders zero
26 br(n)=tempar
bi(n)=tempai
nend=-nend
do 27 l=1,nend
br(n+l)=0.0
27 bi(n+l)=0.0
30 nend=n-2
if(nend.eq.0) go to 33
c calculate via difference equation and store br(n),bi(n)
c until n=2
do 32 l=1,nend
n=n-1
pr=(n+n)*zinvr
pi=(n+n)*zinvi
br(n)=pr*br(n+1)-pi*bi(n+1)-sign1*br(n+2)
bi(n)=pr*bi(n+1)+pi*br(n+1)-sign1*bi(n+2)
imag=(1-imag)*imrecr
k=mlast
mlast=m
m=k*mrecur
if(imag.ne.0) go to 31
sumr=sumr+m*br(n)
sumi=sumi+m*bi(n)
go to 32
31 sumr=sumr-m*bi(n)
sumi=sumi+m*br(n)
32 continue
c calculate and store br(1),bi(1)
33 br(1)=2.0*(br(2)*zinvr-bi(2)*zinvi)-sign1*br(3)
bi(1)=2.0*(br(2)*zinvi+bi(2)*zinvr)-sign1*bi(3)
34 sumr=sumr+br(1)
sumi=sumi+bi(1)
c calculate normalization factor. tempar+i*tempai
35 if(ize.eq.1) go to 36
tempcr=ipos*y
tempci=-ipos*x
go to 37
36 tempcr=ipos*x
tempci=ipos*y
37 tempcr=exp(tempcr)
tempbr=cos(tempci)
tempbi=sin(tempci)
if(abs(sumr).lt.abs(sumi)) go to 38
tempci=sumi/sumr
tempcr=(tempcr/sumr)/(1.0+tempci*tempci)
tempar=tempcr*(tempbr+tempbi*tempci)
tempai=tempcr*(tempbi-tempbr*tempci)
go to 39
38 tempci=sumr/sumi
tempcr=(tempcr/sumi)/(1.0+tempci*tempci)
tempar=tempcr*(tempbr*tempci+tempbi)
tempai=tempcr*(tempbi*tempci-tempbr)
c normalize
39 do 40 n=1,nb
tempbr=br(n)*tempar-bi(n)*tempai
bi(n)=br(n)*tempai+bi(n)*tempar
40 br(n)=tempbr
return
c two-term ascending series for small z
50 tempar=1.0
tempai=0.0
tempcr=0.25*(x*x-y*y)
tempci=0.5*x*y
br(1)=1.0-sign1*tempcr
bi(1)=-sign1*tempci
if(nb.eq.1) go to 52
do 51 n=2,nb
tempbr=(tempar*x-tempai*y)/(n+n-2)
tempai=(tempar*y+tempai*x)/(n+n-2)
tempar=tempbr
tempbr=n
br(n)=tempar*(1.0-sign1*tempcr/tempbr)+tempai*tempci/tempbr
51 bi(n)=tempai*(1.0-sign1*tempcr/tempbr)-tempar*tempci/tempbr
52 return
end
subroutine besj(x,n,bj,d,ier)
c-----------------------------------------------------------------------
c i.b.m. bessel function j
c x - argument
c n - order (integer .ge. 0)
c bj - j(x)
c d - relative allowable error (input)
c ier- error switch, if ier=0 all is ok
c-----------------------------------------------------------------------
bj=0.
if(n) 10,20,20
10 ier=1
return
20 if(x) 30,30,31
30 ier=2
bj=0.
if(n.eq.0) bj=1.
return
31 if(x-15.) 32,32,34
32 ntest=20.+10.*x-x*x/3
go to 36
34 ntest=90.+x/2.
36 if(n-ntest) 40,38,38
38 ier=4
return
40 ier=0
n1=n+1
bprev=0.
if(x-5.) 50,60,60
50 ma=x+6.
go to 70
60 ma=1.4*x+60./x
70 mb=n+ifix(x)/4+2
mzero=max0(ma,mb)
mmax=ntest
100 do 190 m=mzero,mmax,3
fm1=1.e-28
fm=0.
alpha=0.
if(m-(m/2)*2)120,110,120
110 jt=-1
go to 130
120 jt=1
130 m2=m-2
do 160 k=1,m2
mk=m-k
bmk=2.*float(mk)*fm1/x-fm
fm=fm1
fm1=bmk
if(mk-n-1) 150,140,150
140 bj=bmk
150 jt=-jt
s=1+jt
160 alpha=alpha+bmk*s
bmk=2.*fm1/x-fm
if(n) 180,170,180
170 bj=bmk
180 alpha=alpha+bmk
bj=bj/alpha
if(abs(bj-bprev)-abs(d*bj))200,200,190
190 bprev=bj
ier=3
200 return
end
c
c
c88888888888888888888888888888888888888888888888888888888888888888888888888
SUBROUTINE DBESJ(X,ALPHA,N,Y,NZ)
C***BEGIN PROLOGUE DBESJ
C***DATE WRITTEN 750101 (YYMMDD)
C***REVISION DATE 851111 (YYMMDD)
C***CATEGORY NO. C10A3
C***KEYWORDS BESSEL FUNCTION,DOUBLE PRECISION,J BESSEL FUNCTION,
C SPECIAL FUNCTION
C***AUTHOR AMOS, D. E., (Sandia National Laboratories, Albuquerque)
C DANIEL, S. L., (Sandia National Laboratories, Albuquerque)
C WESTON, M. K., (Sandia National Laboratories, Albuquerque)
C***PURPOSE Compute an N member sequence of J Bessel functions
C J/SUB(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA
C and X. (At most 14 digits.)
C***DESCRIPTION
C
C Written by D. E. Amos, S. L. Daniel and M. K. Weston, January 1975
C
C References
C SAND-75-0147
C
C CDC 6600 Subroutines IBESS and JBESS for Bessel Functions
C I(NU,X) and J(NU,X), X .GE. 0, NU .GE. 0 by D. E. Amos, S. L.
C Daniel, M. K. Weston. ACM Trans Math Software,3,pp 76-92
C (1977)
C
C Tables of Bessel Functions of Moderate or Large Orders,
C NPL Mathematical Tables, Vol. 6, by F. W. J. Olver, Her
C Majesty's Stationery Office, London, 1962.
C
C Abstract **** a double precision routine ****
C DBESJ computes an N member sequence of J Bessel functions
C J/sub(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA and X.
C A combination of the power series, the asymptotic expansion
C for X to infinity and the uniform asymptotic expansion for
C NU to infinity are applied over subdivisions of the (NU,X)
C plane. For values of (NU,X) not covered by one of these
C formulae, the order is incremented or decremented by integer
C values into a region where one of the formulae apply. Backward
C recursion is applied to reduce orders by integer values except
C where the entire sequence lies in the oscillatory region. In
C this case forward recursion is stable and values from the
C asymptotic expansion for X to infinity start the recursion
C when it is efficient to do so. Leading terms of the series and
C uniform expansion are tested for underflow. If a sequence is
C requested and the last member would underflow, the result is
C set to zero and the next lower order tried, etc., until a
C member comes on scale or all members are set to zero.
C Overflow cannot occur.
C
C The maximum number of significant digits obtainable
C is the smaller of 14 and the number of digits carried in
C double precision arithmetic.
C
C DBESJ calls DASYJY, DJAIRY, DLNGAM, D1MACH, I1MACH, XERROR
C
C Description of Arguments
C
C Input X,ALPHA are double precision
C X - X .GE. 0.0D0
C ALPHA - order of first member of the sequence,
C ALPHA .GE. 0.0D0
C N - number of members in the sequence, N .GE. 1
C
C Output Y is double precision
C Y - a vector whose first N components contain
C values for J/sub(ALPHA+K-1)/(X), K=1,...,N
C NZ - number of components of Y set to zero due to
C underflow,
C NZ=0 , normal return, computation completed
C NZ .NE. 0, last NZ components of Y set to zero,
C Y(K)=0.0D0, K=N-NZ+1,...,N.
C
C Error Conditions
C Improper input arguments - a fatal error
C Underflow - a non-fatal error (NZ .NE. 0)
C***REFERENCES CDC 6600 SUBROUTINES IBESS AND JBESS FOR BESSEL
C FUNCTIONS I(NU,X) AND J(NU,X), X .GE. 0, NU .GE. 0,
C BY D. E. AMOS, S. L.DANIEL, M. K. WESTON, ACM
C TRANSACTIONS ON MATHEMATICALSOFTWARE, VOL. 3,
C PP. 76-92 (1977).
C***ROUTINES CALLED D1MACH,DASYJY,DJAIRY,DLNGAM,I1MACH,XERROR
C***END PROLOGUE DBESJ
EXTERNAL DJAIRY
INTEGER I,IALP,IDALP,IFLW,IN,INLIM,IS,I1,I2,K,KK,KM,KT,N,NN,
1 NS,NZ
INTEGER I1MACH
DOUBLE PRECISION AK,AKM,ALPHA,ANS,AP,ARG,COEF,DALPHA,DFN,DTM,
1 EARG,ELIM1,ETX,FIDAL,FLGJY,FN,FNF,FNI,FNP1,FNU,
2 FNULIM,GLN,PDF,PIDT,PP,RDEN,RELB,RTTP,RTWO,RTX,RZDEN,
3 S,SA,SB,SXO2,S1,S2,T,TA,TAU,TB,TEMP,TFN,TM,TOL,
4 TOLLN,TRX,TX,T1,T2,WK,X,XO2,XO2L,Y,SLIM,RTOL
DOUBLE PRECISION D1MACH, DLNGAM
DIMENSION Y(*), TEMP(3), FNULIM(2), PP(4), WK(7)
DATA RTWO,PDF,RTTP,PIDT / 1.34839972492648D+00,
1 7.85398163397448D-01, 7.97884560802865D-01, 1.57079632679490D+00/
DATA PP(1), PP(2), PP(3), PP(4) / 8.72909153935547D+00,
1 2.65693932265030D-01, 1.24578576865586D-01, 7.70133747430388D-04/
DATA INLIM / 150 /
DATA FNULIM(1), FNULIM(2) / 100.0D0, 60.0D0 /
C***FIRST EXECUTABLE STATEMENT DBESJ
cBH write(*,*)'DBESJ:x,alpha,n,y(1),nzero',x,alpha,n,y(1),nz
cBH
cBH write(*,*)'DBESJ:D1MACH(1:5)',D1MACH(1),D1MACH(2),D1MACH(3),
cBH + D1MACH(4),D1MACH(5)
NZ = 0
KT = 1
NS=0
C I1MACH(14) REPLACES I1MACH(11) IN A DOUBLE PRECISION CODE
C I1MACH(15) REPLACES I1MACH(12) IN A DOUBLE PRECISION CODE
TA = D1MACH(3)
TOL = DMAX1(TA,1.0D-15)
I1 = I1MACH(14) + 1
I2 = I1MACH(15)
TB = D1MACH(5)
cBH write(*,*)'DBESJ:I1,I2,TB',I1,I2,TB
ELIM1 = 2.303D0*(DBLE(FLOAT(-I2))*TB-3.0D0)
RTOL=1.0D0/TOL
SLIM=D1MACH(1)*RTOL*1.0D+3
C TOLLN = -LN(TOL)
TOLLN = 2.303D0*TB*DBLE(FLOAT(I1))
TOLLN = DMIN1(TOLLN,34.5388D0)
IF (N-1) 720, 10, 20
10 KT = 2
20 NN = N
IF (X) 730, 30, 80
30 IF (ALPHA) 710, 40, 50
40 Y(1) = 1.0D0
IF (N.EQ.1) RETURN
I1 = 2
GO TO 60
50 I1 = 1
60 DO 70 I=I1,N
Y(I) = 0.0D0
70 CONTINUE
RETURN
80 CONTINUE
IF (ALPHA.LT.0.0D0) GO TO 710
C
IALP = INT(SNGL(ALPHA))
FNI = DBLE(FLOAT(IALP+N-1))
FNF = ALPHA - DBLE(FLOAT(IALP))
DFN = FNI + FNF
FNU = DFN
XO2 = X*0.5D0
SXO2 = XO2*XO2
C
C DECISION TREE FOR REGION WHERE SERIES, ASYMPTOTIC EXPANSION FOR X
C TO INFINITY AND ASYMPTOTIC EXPANSION FOR NU TO INFINITY ARE
C APPLIED.
C
IF (SXO2.LE.(FNU+1.0D0)) GO TO 90
TA = DMAX1(20.0D0,FNU)
IF (X.GT.TA) GO TO 120
IF (X.GT.12.0D0) GO TO 110
XO2L = DLOG(XO2)
NS = INT(SNGL(SXO2-FNU)) + 1
GO TO 100
90 FN = FNU
FNP1 = FN + 1.0D0
XO2L = DLOG(XO2)
IS = KT
IF (X.LE.0.50D0) GO TO 330
NS = 0
100 FNI = FNI + DBLE(FLOAT(NS))
DFN = FNI + FNF
FN = DFN
FNP1 = FN + 1.0D0
IS = KT
IF (N-1+NS.GT.0) IS = 3
GO TO 330
110 ANS = DMAX1(36.0D0-FNU,0.0D0)
NS = INT(SNGL(ANS))
FNI = FNI + DBLE(FLOAT(NS))
DFN = FNI + FNF
FN = DFN
IS = KT
IF (N-1+NS.GT.0) IS = 3
GO TO 130
120 CONTINUE
RTX = DSQRT(X)
TAU = RTWO*RTX
TA = TAU + FNULIM(KT)
IF (FNU.LE.TA) GO TO 480
FN = FNU
IS = KT
C
C UNIFORM ASYMPTOTIC EXPANSION FOR NU TO INFINITY
C
130 CONTINUE
I1 = IABS(3-IS)
I1 = MAX0(I1,1)
FLGJY = 1.0D0
CALL DASYJY(DJAIRY,X,FN,FLGJY,I1,TEMP(IS),WK,IFLW)
IF(IFLW.NE.0) GO TO 380
GO TO (320, 450, 620), IS
310 TEMP(1) = TEMP(3)
KT = 1
320 IS = 2
FNI = FNI - 1.0D0
DFN = FNI + FNF
FN = DFN
IF(I1.EQ.2) GO TO 450
GO TO 130
C
C SERIES FOR (X/2)**2.LE.NU+1
C
330 CONTINUE
GLN = DLNGAM(FNP1)
ARG = FN*XO2L - GLN
IF (ARG.LT.(-ELIM1)) GO TO 400
EARG = DEXP(ARG)
340 CONTINUE
S = 1.0D0
IF (X.LT.TOL) GO TO 360
AK = 3.0D0
T2 = 1.0D0
T = 1.0D0
S1 = FN
DO 350 K=1,17
S2 = T2 + S1
T = -T*SXO2/S2
S = S + T
IF (DABS(T).LT.TOL) GO TO 360
T2 = T2 + AK
AK = AK + 2.0D0
S1 = S1 + FN
350 CONTINUE
360 CONTINUE
TEMP(IS) = S*EARG
GO TO (370, 450, 610), IS
370 EARG = EARG*FN/XO2
FNI = FNI - 1.0D0
DFN = FNI + FNF
FN = DFN
IS = 2
GO TO 340
C
C SET UNDERFLOW VALUE AND UPDATE PARAMETERS
C UNDERFLOW CAN ONLY OCCRFOR NS=0 SINCE THE ORDER MUST BE LARGER
C THAN 36. THEREFORE, NS NEE NOT BE TESTED.
C
380 Y(NN) = 0.0D0
NN = NN - 1
FNI = FNI - 1.0D0
DFN = FNI + FNF
FN = DFN
IF (NN-1) 440, 390, 130
390 KT = 2
IS = 2
GO TO 130
400 Y(NN) = 0.0D0
NN = NN - 1
FNP1 = FN
FNI = FNI - 1.0D0
DFN = FNI + FNF
FN = DFN
IF (NN-1) 440, 410, 420
410 KT = 2
IS = 2
420 IF (SXO2.LE.FNP1) GO TO 430
GO TO 130
430 ARG = ARG - XO2L + DLOG(FNP1)
IF (ARG.LT.(-ELIM1)) GO TO 400
GO TO 330
440 NZ = N - NN
cBH write(*,*)'**0**DBESJ:Y(1)',Y(1)
RETURN
C
C BACKWARD RECURSION SECTION
C
450 CONTINUE
IF(NS.NE.0) GO TO 451
NZ = N - NN
IF (KT.EQ.2) GO TO 470
C BACKWARD RECUR FROM INDEX ALPHA+NN-1 TO ALPHA
Y(NN) = TEMP(1)
Y(NN-1) = TEMP(2)
cBH write(*,*)'**0.1**DBESJ:Y(1)',Y(1)
IF (NN.EQ.2) RETURN
451 CONTINUE
TRX = 2.0D0/X
DTM = FNI
TM = (DTM+FNF)*TRX
AK=1.0D0
TA=TEMP(1)
TB=TEMP(2)
IF(DABS(TA).GT.SLIM) GO TO 455
TA=TA*RTOL
TB=TB*RTOL
AK=TOL
455 CONTINUE
KK=2
IN=NS-1
IF(IN.EQ.0) GO TO 690
IF(NS.NE.0) GO TO 670
K=NN-2
DO 460 I=3,NN
S=TB
TB = TM*TB - TA
TA=S
Y(K)=TB*AK
DTM = DTM - 1.0D0
TM = (DTM+FNF)*TRX
K = K - 1
460 CONTINUE
RETURN
470 Y(1) = TEMP(2)
cBH write(*,*)'**0.2**DBESJ:Y(1)',Y(1)
RETURN
C
C ASYMPTOTIC EXPANSION FOR X TO INFINITY WITH FORWARD RECURSION IN
C OSCILLATORY REGION X.GT.MAX(20, NU), PROVIDED THE LAST MEMBER
C OF THE SEQUENCE IS ALSO IN THE REGION.
C
480 CONTINUE
IN = INT(SNGL(ALPHA-TAU+2.0D0))
IF (IN.LE.0) GO TO 490
IDALP = IALP - IN - 1
KT = 1
GO TO 500
490 CONTINUE
IDALP = IALP
IN = 0
500 IS = KT
FIDAL = DBLE(FLOAT(IDALP))
DALPHA = FIDAL + FNF
ARG = X - PIDT*DALPHA - PDF
SA = DSIN(ARG)
SB = DCOS(ARG)
COEF = RTTP/RTX
ETX = 8.0D0*X
510 CONTINUE
DTM = FIDAL + FIDAL
DTM = DTM*DTM
TM = 0.0D0
IF (FIDAL.EQ.0.0D0 .AND. DABS(FNF).LT.TOL) GO TO 520
TM = 4.0D0*FNF*(FIDAL+FIDAL+FNF)
520 CONTINUE
TRX = DTM - 1.0D0
T2 = (TRX+TM)/ETX
S2 = T2
RELB = TOL*DABS(T2)
T1 = ETX
S1 = 1.0D0
FN = 1.0D0
AK = 8.0D0
DO 530 K=1,13
T1 = T1 + ETX
FN = FN + AK
TRX = DTM - FN
AP = TRX + TM
T2 = -T2*AP/T1
S1 = S1 + T2
T1 = T1 + ETX
AK = AK + 8.0D0
FN = FN + AK
TRX = DTM - FN
AP = TRX + TM
T2 = T2*AP/T1
S2 = S2 + T2
IF (DABS(T2).LE.RELB) GO TO 540
AK = AK + 8.0D0
530 CONTINUE
540 TEMP(IS) = COEF*(S1*SB-S2*SA)
IF(IS.EQ.2) GO TO 560
FIDAL = FIDAL + 1.0D0
DALPHA = FIDAL + FNF
IS = 2
TB = SA
SA = -SB
SB = TB
GO TO 510
C
C FORWARD RECURSION SECTION
C
560 IF (KT.EQ.2) GO TO 470
S1 = TEMP(1)
S2 = TEMP(2)
TX = 2.0D0/X
TM = DALPHA*TX
IF (IN.EQ.0) GO TO 580
C
C FORWARD RECUR TO INDEX ALPHA
C
DO 570 I=1,IN
S = S2
S2 = TM*S2 - S1
TM = TM + TX
S1 = S
570 CONTINUE
IF (NN.EQ.1) GO TO 600
S = S2
S2 = TM*S2 - S1
TM = TM + TX
S1 = S
580 CONTINUE
C
C FORWARD RECUR FROM INDEX ALPHA TO ALPHA+N-1
C
Y(1) = S1
Y(2) = S2
IF (NN.EQ.2) RETURN
DO 590 I=3,NN
Y(I) = TM*Y(I-1) - Y(I-2)
TM = TM + TX
590 CONTINUE
cBH write(*,*)'**0.3**DBESJ:Y(1)',Y(1)
RETURN
600 Y(1) = S2
cBH write(*,*)'**1**DBESJ:Y(1)',Y(1)
RETURN
C
C BACKWARD RECURSION WITH NORMALIZATION BY
C ASYMPTOTIC EXPANSION FOR NU TO INFINITY OR POWER SERIES.
C
610 CONTINUE
C COMPUTATION OF LAST ORDER FOR SERIES NORMALIZATION
AKM = DMAX1(3.0D0-FN,0.0D0)
KM = INT(SNGL(AKM))
TFN = FN + DBLE(FLOAT(KM))
TA = (GLN+TFN-0.9189385332D0-0.0833333333D0/TFN)/(TFN+0.5D0)
TA = XO2L - TA
TB = -(1.0D0-1.5D0/TFN)/TFN
AKM = TOLLN/(-TA+DSQRT(TA*TA-TOLLN*TB)) + 1.5D0
IN = KM + INT(SNGL(AKM))
GO TO 660
620 CONTINUE
C COMPUTATION OF LAST ORDER FOR ASYMPTOTIC EXPANSION NORMALIZATION
GLN = WK(3) + WK(2)
IF (WK(6).GT.30.0D0) GO TO 640
RDEN = (PP(4)*WK(6)+PP(3))*WK(6) + 1.0D0
RZDEN = PP(1) + PP(2)*WK(6)
TA = RZDEN/RDEN
IF (WK(1).LT.0.10D0) GO TO 630
TB = GLN/WK(5)
GO TO 650
630 TB=(1.259921049D0+(0.1679894730D0+0.0887944358D0*WK(1))*WK(1))
1 /WK(7)
GO TO 650
640 CONTINUE
TA = 0.5D0*TOLLN/WK(4)
TA=((0.0493827160D0*TA-0.1111111111D0)*TA+0.6666666667D0)*TA*WK(6)
IF (WK(1).LT.0.10D0) GO TO 630
TB = GLN/WK(5)
650 IN = INT(SNGL(TA/TB+1.5D0))
IF (IN.GT.INLIM) GO TO 310
660 CONTINUE
DTM = FNI + DBLE(FLOAT(IN))
TRX = 2.0D0/X
TM = (DTM+FNF)*TRX
TA = 0.0D0
TB = TOL
KK = 1
AK=1.0D0
670 CONTINUE
C
C BACKWARD RECUR UNINDEXED
C
DO 680 I=1,IN
S = TB
TB = TM*TB - TA
TA = S
DTM = DTM - 1.0D0
TM = (DTM+FNF)*TRX
680 CONTINUE
C NORMALIZATION
IF (KK.NE.1) GO TO 690
S=TEMP(3)
SA=TA/TB
TA=S
TB=S
IF(DABS(S).GT.SLIM) GO TO 685
TA=TA*RTOL
TB=TB*RTOL
AK=TOL
685 CONTINUE
TA=TA*SA
KK = 2
IN = NS
IF (NS.NE.0) GO TO 670
690 Y(NN) = TB*AK
NZ = N - NN
cBH write(*,*)'**1.1**DBESJ:Y(1)',Y(1)
IF (NN.EQ.1) RETURN
K = NN - 1
S=TB
TB = TM*TB - TA
TA=S
Y(K)=TB*AK
cBH write(*,*)'**1.2**DBESJ:Y(1)',Y(1)
IF (NN.EQ.2) RETURN
DTM = DTM - 1.0D0
TM = (DTM+FNF)*TRX
K=NN-2
C
C BACKWARD RECUR INDEXED
C
DO 700 I=3,NN
S=TB
TB = TM*TB - TA
TA=S
Y(K)=TB*AK
DTM = DTM - 1.0D0
TM = (DTM+FNF)*TRX
K = K - 1
700 CONTINUE
cBH write(*,*)'**2**DBESJ:Y(1)',Y(1)
RETURN
C
C
C
710 CONTINUE
CALL XERROR('DBESJ - ORDER, ALPHA, LESS THAN ZERO.', 37, 2, 1)
RETURN
720 CONTINUE
CALL XERROR('DBESJ - N LESS THAN ONE.', 24, 2, 1)
RETURN
730 CONTINUE
CALL XERROR('DBESJ - X LESS THAN ZERO.', 25, 2, 1)
RETURN
END
SUBROUTINE DJAIRY(X,RX,C,AI,DAI)
C***BEGIN PROLOGUE DJAIRY
C***REFER TO DBESJ,DBESY
C
C 1-2-74
C DJAIRY computes the Airy function AI(X)
C and its derivative DAI(X) for DASYJY
C
C INPUT
C
C X - Argument, computed by DASYJY, X unrestricted
C RX - RX=DSQRT(DABS(X)), computed by DASYJY
C C - C=2.*(DABS(X)**1.5)/3., computed by DASYJY
C
C OUTPUT
C
C AI - Value of function AI(X)
C DAI - Value of the derivative DAI(X)
C
C Written by
C
C D. E. Amos
C S. L. Daniel
C M. K. Weston
C***ROUTINES CALLED (NONE)
C***END PROLOGUE DJAIRY
C
INTEGER I, J, M1, M1D, M2, M2D, M3, M3D, M4, M4D, N1, N1D, N2,
1 N2D, N3, N3D, N4, N4D
DOUBLE PRECISION A,AI,AJN,AJP,AK1,AK2,AK3,B,C,CCV,CON1,CON2,
1 CON3, CON4, CON5, CV, DA, DAI, DAJN, DAJP, DAK1, DAK2, DAK3,
2 DB, EC, E1, E2, FPI12, F1, F2, RTRX, RX, SCV, T, TEMP1, TEMP2,
3 TT, X
DIMENSION AJP(19), AJN(19), A(15), B(15)
DIMENSION AK1(14), AK2(23), AK3(14)
DIMENSION DAJP(19), DAJN(19), DA(15), DB(15)
DIMENSION DAK1(14), DAK2(24), DAK3(14)
SAVE N1, N2, N3, N4, M1, M2, M3, M4, FPI12, CON1, CON2, CON3,
1 CON4, CON5, AK1, AK2, AK3, AJP, AJN, A, B,
2 N1D, N2D, N3D, N4D, M1D, M2D, M3D, M4D, DAK1, DAK2, DAK3,
3 DAJP, DAJN, DA, DB
DATA N1,N2,N3,N4/14,23,19,15/
DATA M1,M2,M3,M4/12,21,17,13/
DATA FPI12,CON1,CON2,CON3,CON4,CON5/
1 1.30899693899575D+00, 6.66666666666667D-01, 5.03154716196777D+00,
2 3.80004589867293D-01, 8.33333333333333D-01, 8.66025403784439D-01/
DATA AK1(1), AK1(2), AK1(3), AK1(4), AK1(5), AK1(6), AK1(7),
1 AK1(8), AK1(9), AK1(10),AK1(11),AK1(12),AK1(13),
2 AK1(14) / 2.20423090987793D-01,-1.25290242787700D-01,
3 1.03881163359194D-02, 8.22844152006343D-04,-2.34614345891226D-04,
4 1.63824280172116D-05, 3.06902589573189D-07,-1.29621999359332D-07,
5 8.22908158823668D-09, 1.53963968623298D-11,-3.39165465615682D-11,
6 2.03253257423626D-12,-1.10679546097884D-14,-5.16169497785080D-15/
DATA AK2(1), AK2(2), AK2(3), AK2(4), AK2(5), AK2(6), AK2(7),
1 AK2(8), AK2(9), AK2(10),AK2(11),AK2(12),AK2(13),AK2(14),
2 AK2(15),AK2(16),AK2(17),AK2(18),AK2(19),AK2(20),AK2(21),
3 AK2(22),AK2(23) / 2.74366150869598D-01, 5.39790969736903D-03,
4-1.57339220621190D-03, 4.27427528248750D-04,-1.12124917399925D-04,
5 2.88763171318904D-05,-7.36804225370554D-06, 1.87290209741024D-06,
6-4.75892793962291D-07, 1.21130416955909D-07,-3.09245374270614D-08,
7 7.92454705282654D-09,-2.03902447167914D-09, 5.26863056595742D-10,
8-1.36704767639569D-10, 3.56141039013708D-11,-9.31388296548430D-12,
9 2.44464450473635D-12,-6.43840261990955D-13, 1.70106030559349D-13,
1-4.50760104503281D-14, 1.19774799164811D-14,-3.19077040865066D-15/
DATA AK3(1), AK3(2), AK3(3), AK3(4), AK3(5), AK3(6), AK3(7),
1 AK3(8), AK3(9), AK3(10),AK3(11),AK3(12),AK3(13),
2 AK3(14) / 2.80271447340791D-01,-1.78127042844379D-03,