-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchfun.for
4640 lines (4567 loc) · 123 KB
/
chfun.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 Copyright 2017, Christian Hafner
c
c This file is part of OpenMaXwell.
c
c OpenMaXwell is free software: you can redistribute it and/or modify
c it under the terms of the GNU General Public License as published by
c the Free Software Foundation, either version 3 of the License, or
c (at your option) any later version.
c OpenMaXwell is distributed in the hope that it will be useful,
c but WITHOUT ANY WARRANTY; without even the implied warranty of
c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c GNU General Public License for more details.
c You should have received a copy of the GNU General Public License
c along with OpenMaXwell. If not, see <http://www.gnu.org/licenses/>.
c LEGENDRE FUNCTIONS
subroutine legenm(cost,sint,p,l,m)
c legendre functions of degree m and order l=m..l
implicit none
Integer(4) l,m,i,iord
Real(8) cost,sint,p(0:l),p0
if(m.eq.0) then
c compute p(0,l)
if(l.eq.0) then
c l=0
p(0)=1.0d0
return
endif
p(0)=1.0d0
p(1)=cost
do i=1,l-1
p(i+1)=1.0d0/dble(i+1)*(dble(2*i+1)*cost*p(i)-dble(i)*p(i-1))
end do
else
c l>0
p0=-1.0d0
do i=2,m
p0=-dble(2*i-1)*sint*p0
end do
p(0)=p0
if(l.gt.m) then
p(1)=dble(2*m+1)*cost*p(0)
iord=m+1
do i=1,l-m-1
p(i+1)=1.0d0/dble(iord-m+1)*
1 (dble(2*iord+1)*cost*p(i)-dble(m+iord)*p(i-1))
iord=iord+1
end do
end if
end if
end
subroutine legenmC(cost,sint,p,l,m)
c legendre functions of degree m and order l=m..l
implicit none
Integer(4) l,m,i,iord
Complex(8) cost,sint,p(0:l),p0
if(m.eq.0) then
c compute p(0,l)
if(l.eq.0) then
c l=0
p(0)=1.0d0
return
endif
p(0)=1.0d0
p(1)=cost
do i=1,l-1
p(i+1)=1.0d0/dble(i+1)*(dble(2*i+1)*cost*p(i)-dble(i)*p(i-1))
end do
else
c m>0
p0=-1.0d0
do i=2,m
p0=-dble(2*i-1)*sint*p0
end do
p(0)=p0
if(l.gt.m) then
p(1)=dble(2*m+1)*cost*p(0)
iord=m+1
do i=1,l-m-1
p(i+1)=1.0d0/dble(iord-m+1)*
1 (dble(2*iord+1)*cost*p(i)-dble(m+iord)*p(i-1))
iord=iord+1
end do
end if
end if
end
c SPHERICAL BESSEL FUNCTIONS
subroutine vkfnor(r,ll,mm)
c scaling factors for vector spherical harmonics for degree m and order l=m..l
c values: r(m,m)..r(l,m) stored in r(1)..r(l-m+1)
c r: scaling factors
c l: order
c m: degree
implicit none
Integer(4) ll,mm,l,m,i,j
Real(8) r(ll-mm+1),pi,fak
Real(8), external:: dsqrtc
Data pi/3.1415926535898d0/
l=ll
m=mm
c l>=!m
if(l.lt.m) l=m
if(l.le.0) l=1
c start mit r(m,m)
c fakultaet
fak=1.0d0
do i=2,2*m
fak=fak*dble(i)
end do
if(m.eq.0) fak=fak*2.0d0
fak=1.0d0/fak
c faktoren
j=1
do i=m,l
if(i.ne.0) then
r(j)=dsqrtc(dble(2*i+1)/dble(2*i*(i+1))/pi*fak)
fak=fak*dble(i+1-m)/dble(i+1+m)
else
r(j)=0.0d0
endif
j=j+1
end do
end
subroutine Bessel(n,z,cb,icode)
c spherical bessel functions
c icode=1 bessel j
c icode=2 neumann y
c icode=3 hankel 1 h1
c icode=4 hankel 2 h2
c icode=0 hankel 1 h1 with cut on the negative imaginary axis
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
complex(8) cb(0:n),z,cw(101),zj,zs,c
Data zwpi,wpi2/0.63661977236758d0,1.2533141373155d0/
ic=iabs(icode)
fnu=0.5d0
n1=n+1
if(cdabs(z).lt.1.0d-300) then
zs=wpi2/dsqrt(1.0d-300)
else
zs=wpi2/cdsqrt(z)
end if
if(ic.eq.1) then
call zjr(fnu,z,n1,.false.,cb(0),nz,ier)
else if(ic.eq.2) then
call zyr(fnu,z,n1,.false.,cb(0),nz,cw(1),ier)
else if(ic.eq.3) then
call zhr(1,fnu,z,n1,.false.,cb(0),nz,ier)
else if(ic.eq.4) then
call zhr(2,fnu,z,n1,.false.,cb(0),nz,ier)
else
zj=(0.0d0,1.0d0)*z
call zkr(fnu,zj,n1,.false.,cb(0),nz,ier)
c=(0.0d0,-1.0d0)
do i=0,n
zj=c*cb(i)
cb(i)=zwpi*zj
c=(0.0d0,-1.0d0)*c
end do
end if
do i=0,n
c=cb(i)
cb(i)=zs*c
end do
end
c BESSEL FUNCTIONS OF INTEGER ORDERS
subroutine cj(z,cb,n,nmax,ns,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,cb(nmax)
idum=ns
fnu=0.0d0
call zjr(fnu,z,n,.false.,cb(1),nz,ier)
nmax=n-nz
end
subroutine cy(z,cb,n,nmax,ns,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,cb(nmax),cw(100)
idum=ns
nn=n
if(nn.gt.100) nn=100
fnu=0.0d0
call zyr(fnu,z,n,.false.,cb(1),nz,cw(1),ier)
nmax=nn-nz
if((nn.gt.100).and.(ier.eq.0)) ier=-1
end
subroutine ch1(z,hn,n,nmax,ns,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,zj,jn,hn(nmax)
Data zwpi/0.63661977236758d0/
zj=(0.0d0,-1.0d0)*z
call ck(zj,hn,n,nmax,ns,ier)
jn=(0.0d0,-1.0d0)
do i=1,n
zj=jn*hn(i)
hn(i)=zwpi*zj
jn=(0.0d0,-1.0d0)*jn
end do
end
subroutine ch2(z,hn,n,nmax,ns,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,z0,hn(nmax)
z0=DConjg(z)
call ch1(z0,hn,n,nmax,ns,ier)
do i=1,n
hn(i)=DConjg(hn(i))
end do
end
subroutine ch1a(z,cb,n,nmax,ns,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,cb(nmax)
idum=ns
fnu=0.0d0
call zhr(1_4,fnu,z,n,.false.,cb(1),nz,ier)
nmax=n-nz
end
subroutine ci(z,cb,n,nmax,ns,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,cb(nmax)
idum=ns
fnu=0.0d0
call zir(fnu,z,n,.false.,cb(1),nz,ier)
nmax=n-nz
end
subroutine ck(z,cb,n,nmax,ns,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,cb(nmax)
idum=ns
fnu=0.0d0
call zkr(fnu,z,n,.false.,cb,nz,ier)
nmax=n-nz
end
c BESSEL FUNCTIONS OF REAL ORDERS
subroutine zjr(fnuu,z,nn,scale,cy,nz,ier)
c bessel functions cy(i)=j(fnu+i-1,z) (scale=false) or scaled bessel
c functions cy(i)=exp(-abs(y))*j(fnu+i-1,z) with complez argument z
c for real, nonnegative orders fnu+i-1,i=1,...,n
c nz: zero terms due to underflow, ier: error flag
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Integer(4), intent(in) :: nn
Integer(4), intent(out) :: nz,ier
Real(8), intent(in) :: fnuu
Complex(8) z,cy(nn),ci,csgn,zn
Logical scale
Data hpi/1.57079632679489662d0/
fnu=fnuu
if(fnu.lt.0.0d0) fnu=-fnu
n=nn
if(n.lt.1) n=1
ier=0_4
nz=0_4
aa=1073741823.0d0
ci=dcmplx(0.0d0,1.0d0)
yy=dimag(z)
az=abs(z)
fn=fnu+dble(n-1)
if(az.le.aa) then
if(fn.le.aa) then
aa=sqrt(aa)
if((az.gt.aa).or.(fn.gt.aa)) ier=-1
inu=int(fnu)
inuh=inu/2
ir=inu-2*inuh
arg=(fnu-inu+ir)*hpi
r1=cos(arg)
r2=sin(arg)
csgn=dcmplx(r1,r2)
if(mod(inuh,2).eq.1) csgn=-csgn
zn=-z*ci
if(yy.lt.0.0d0) then
zn=-zn
csgn=dconjg(csgn)
ci=dconjg(ci)
endif
call zir0(zn,fnu,scale,n,cy,nz)
if(nz.ge.0) then
nl=n-nz
if(nl.ne.0) then
rtol=1.0d16
ascle=dexp(-700.0d0)*rtol
do 1 i=1,nl
zn=cy(i)
aa=dble(zn)
bb=dimag(zn)
atol=1.0d0
if(max(abs(aa),abs(bb)).le.ascle) then
zn=zn*rtol
atol=1.0d-16
endif
zn=zn*csgn
cy(i)=zn*atol
csgn=csgn*ci
1 continue
endif
else
nz=0
ier=1
endif
else
nz=0
ier=1
endif
endif
end
subroutine zyr(fnuu,zz,nn,scale,cy,nz,cwrk,ier)
c neumann functions cy(i)=y(fnu+i-1,z) (scale=false) or scaled neumann
c functions cy(i)=exp(-abs(y))*y(fnu+i-1,z) with complez argument z
c for real, nonnegative orders fnu+i-1,i=1,...,n
c nz: zero terms due to underflow, ier: error flag
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Integer(4), intent(in) :: nn
Integer(4), intent(out) :: nz,ier
Complex(8) zz,z,cwrk(nn),cy(nn),c1,c2,ex,hci,zu,zv
Logical scale
ier=0_4
nz=0_4
z=zz
xx=dble(z)
yy=dimag(z)
if(abs(xx).lt.1.0d-307.and.abs(yy).lt.1.0d-307) then
z=(1.0d-307,0.0d0)
xx=dble(z)
yy=dimag(z)
end if
fnu=fnuu
if(fnu.lt.0.0d0) fnu=-fnu
n=nn
if(n.lt.1) n=1
hci=dcmplx(0.0d0,0.5d0)
call zhr(1_4,fnu,z,n,scale,cy,nz1,ier)
if(ier.lt.1) then
call zhr(2_4,fnu,z,n,scale,cwrk,nz2,ier)
if(ier.lt.1) then
nz=min(nz1,nz2)
if(scale) then
r1=cos(xx)
r2=sin(xx)
ex=dcmplx(r1,r2)
ey=0.0d0
tay=abs(yy+yy)
if(tay.lt.700.0d0) ey=dexp(-tay)
if(yy.lt.0.0d0) then
c1=ex
c2=dconjg(ex)*dcmplx(ey,0.0d0)
else
c1=ex*dcmplx(ey,0.0d0)
c2=dconjg(ex)
endif
nz=0
rtol=1.0d16
ascle=dexp(-700.0d0)*rtol
do 1 i=1,n
zv=cwrk(i)
aa=dble(zv)
bb=dimag(zv)
atol=1.0d0
if(max(abs(aa),abs(bb)).le.ascle) then
zv=zv*rtol
atol=1.0d-16
endif
zv=zv*c2*hci
zv=zv*atol
zu=cy(i)
aa=dble(zu)
bb=dimag(zu)
atol=1.0d0
if(max(abs(aa),abs(bb)).le.ascle) then
zu=zu*rtol
atol=1.0d-16
endif
zu=zu*c1*hci
zu=zu*atol
cy(i)=zv-zu
if(cy(i).eq.dcmplx(0.0d0,0.0d0).and.ey.eq.0.0d0) nz=nz+1
1 continue
else
do 2 i=1,n
cy(i)=hci*(cwrk(i)-cy(i))
2 continue
endif
endif
endif
end
subroutine zhr(mm,fnuu,zz,nn,scale,cy,nz,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Integer(4), intent(in) :: nn,mm
Integer(4), intent(out) :: nz,ier
Complex(8) z,zz,cy(nn),csgn,zn,zt
Logical scale
Data hpi/1.57079632679489662d0/
ier=0_4
nz=0_4
z=zz
xx=dble(z)
yy=dimag(z)
if(abs(xx).lt.1.0d-307.and.abs(yy).lt.1.0d-307) then
z=(1.0d-307,0.0d0)
xx=dble(z)
yy=dimag(z)
end if
fnu=fnuu
if(fnu.lt.0.0d0) fnu=-fnu
n=nn
if(n.lt.1) n=1
m=2
if(mm.lt.2) m=1
nnn=n
aa=1073741823.0d0
fn=fnu+dble(nnn-1)
mmm=3-2*m
fmm=dble(mmm)
zn=z*dcmplx(0.0d0,-fmm)
xn=dble(zn)
yn=dimag(zn)
az=abs(z)
if(az.le.aa) then
if(fn.le.aa) then
aa=sqrt(aa)
if((az.gt.aa).or.(fn.gt.aa)) ier=-1
ufl=dexp(-700.0d0)
if(az.ge.ufl) then
if(fnu.gt.82.0d0) then
mr=0
if((xn.lt.0.0d0).or.(xn.eq.0.0d0.and.yn.lt.0.0d0
* .and.m.eq.2)) then
mr=-m
if(xn.eq.0.0d0.and.yn.lt.0.0d0) zn=-zn
endif
call zkrua(zn,fnu,scale,mr,nnn,cy,nw)
if(nw.lt.0) then
goto 9
else
nz=nz+nw
endif
else
if(fn.gt.1.0d0) then
if(fn.gt.2.0d0) then
call zikrp1(zn,fnu,scale,2_4,nnn,cy,nuf)
if(nuf.lt.0) goto 9
nz=nz+nuf
nnn=nnn-nuf
if(nnn.eq.0) then
if(xn.lt.0.0d0) goto 9
return
endif
elseif(az.le.1.0d-16) then
arg=0.5d0*az
aln=-fn*dlog(arg)
if(aln.gt.700.0d0) goto 9
endif
endif
if((xn.lt.0.0d0).or.(xn.eq.0.0d0.and.yn.lt.0.0d0
* .and.m.eq.2)) then
mr=-mmm
call zkrc(zn,fnu,scale,mr,nnn,cy,nw)
if(nw.lt.0) then
goto 9
else
nz=nw
endif
else
call zkr0(zn,fnu,scale,nnn,cy,nz)
endif
endif
sgn=sign(hpi,-fmm)
inu=int(fnu)
inuh=inu/2
ir=inu-2*inuh
arg =(fnu-inu+ir)*sgn
rhpi=1.0d0/sgn
cpn=rhpi*cos(arg)
spn=rhpi*sin(arg)
csgn=dcmplx(-spn,cpn)
if(mod(inuh,2).eq.1) csgn=-csgn
zt=dcmplx(0.0d0,-fmm)
rtol=1.0d16
ascle=ufl*rtol
do 1 i=1,nnn
zn=cy(i)
aa=dble(zn)
bb=dimag(zn)
atol=1.0d0
if(max(abs(aa),abs(bb)).le.ascle) then
zn=zn*rtol
atol=1.0d-16
endif
zn=zn*csgn
cy(i)=zn*atol
csgn=csgn*zt
1 continue
return
endif
endif
endif
9 nz=0
ier=1
end
subroutine zir(fnuu,z,nn,scale,cy,nz,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Integer(4), intent(in) :: nn
Integer(4), intent(out) :: nz,ier
Complex(8) z,cy(nn),cone,csgn,zn
Logical scale
Data cone/(1.0d0,0.0d0)/
Data pi/3.14159265358979324d0/
ier=0
nz=0
fnu=fnuu
if(fnu.lt.0.0d0) fnu=-fnu
n=nn
if(n.lt.1) n=1
xx=dble(z)
yy=dimag(z)
aa=1073741823.0d0
az=abs(z)
if(az.le.aa) then
fn=fnu+dble(n-1)
if(fn.le.aa) then
aa=sqrt(aa)
if((az.gt.aa).or.(fn.gt.aa)) ier=-1
zn=z
csgn=cone
if(xx.lt.0.0d0) then
zn=-z
inu=int(fnu)
arg=(fnu-inu)*pi
if(yy.lt.0.0d0) arg=-arg
s1=cos(arg)
s2=sin(arg)
csgn=dcmplx(s1,s2)
if(mod(inu,2).eq.1) csgn=-csgn
endif
call zir0(zn,fnu,scale,n,cy,nz)
if(nz.lt.0) then
if(nz.eq.(-3)) goto 9
elseif(xx.lt.0.0d0) then
nnn=n-nz
if(nnn.ne.0) then
rtol=1.0d16
ascle=dexp(-700.0d0)*rtol
do 1 i=1,nnn
zn=cy(i)
aa=dble(zn)
bb=dimag(zn)
atol=1.0d0
if(max(abs(aa),abs(bb)).le.ascle) then
zn=zn*rtol
atol=1.0d-16
endif
zn=zn*csgn
cy(i)=zn*atol
csgn=-csgn
1 continue
endif
endif
return
endif
endif
9 nz=0
ier=1
end
subroutine zkr(fnuu,zz,nn,scale,cy,nz,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Integer(4), intent(in) :: nn
Integer(4), intent(out) :: nz,ier
Complex(8) z,zz,cy(nn)
Logical scale
ier=0_4
nz=0_4
z=zz
xx=dble(z)
yy=dimag(z)
if(abs(xx).lt.1.0d-307.and.abs(yy).lt.1.0d-307) then
z=(1.0d-307,0.0d0)
xx=dble(z)
yy=dimag(z)
end if
fnu=fnuu
if(fnu.lt.0.0d0) fnu=-fnu
n=nn
if(n.lt.1) n=1
nnn=n
aa=1073741823.0d0
az=abs(z)
fn=fnu+dble(nnn-1)
if(az.le.aa) then
if(fn.le.aa) then
aa=sqrt(aa)
if((az.gt.aa).or.(fn.gt.aa)) ier=-1
ufl=dexp(-700.0d0)
if(az.ge.ufl) then
if(fnu.gt.82.0d0) then
mr=0
if(xx.lt.0.0d0) then
mr=1
if(yy.lt.0.0d0) mr=-1
endif
call zkrua(z,fnu,scale,mr,nnn,cy,nw)
if(nw.ge.0) then
nz=nz+nw
return
endif
else
if(fn.gt.1.0d0) then
if(fn.gt.2.0d0) then
call zikrp1(z,fnu,scale,2_4,nnn,cy,nuf)
if(nuf.lt.0) goto 9
nz=nz+nuf
nnn=nnn-nuf
if(nnn.eq.0) then
if(xx.lt.0.0d0) goto 9
return
endif
elseif(az.le.1.0d-16) then
arg=0.5d0*az
aln=-fn*dlog(arg)
if(aln.gt.700.0d0) goto 9
endif
endif
if(xx.lt.0.0d0) then
if(nz.ne.0) goto 9
mr=1
if(yy.lt.0.0d0) mr=-1
call zkrc(z,fnu,scale,mr,nnn,cy,nw)
if(nw.ge.0) then
nz=nw
return
endif
else
call zkr0(z,fnu,scale,nnn,cy,nw)
if(nw.ge.0) then
nz=nw
return
endif
endif
endif
endif
endif
endif
9 nz=0
ier=1
end
subroutine zairy(deriv,z,scale,ai,nz,ier)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) ai,z,cy(1),cone,csq,s1,s2,trm1,trm2,z3,zta,zexp
Logical, intent(in) :: scale,deriv
External zexp
Data cone/(1.0d0,0.0d0)/
Data tth,c1,c2,coef/6.66666666666666667d-01,
* 3.55028053887817240d-01,
* 2.58819403792806799d-01,
* 1.83776298473930683d-01/
ier=0
nz=0
az=abs(z)
if(az.gt.1.0d0) then
fnu=1.0d0/3.0d0
if(deriv) fnu=2.0d0*fnu
aa=1073741823.0d0
alaz=dlog(az)
aa=aa**tth
if(az.gt.aa) goto 9
aa=sqrt(aa)
if(az.gt.aa) ier=-1
csq=sqrt(z)
zta=z*csq*dcmplx(tth,0.0d0)
iflag=0
sfac=1.0d0
zi=dimag(z)
zr=dble(z)
ak=dimag(zta)
if(zr.lt.0.0d0) then
bk=dble(zta)
ck=-abs(bk)
zta=dcmplx(ck,ak)
endif
if((zi.eq.0.0d0).and.(zr.le.0.0d0)) zta=dcmplx(0.0d0,ak)
aa=dble(zta)
if(aa.ge.0.0d0.and.zr.gt.0.0d0) then
if(scale) then
if(aa.ge.664.0d0) then
aa=-aa-0.25d0*alaz
iflag=2
sfac=1.0d16
if(aa.lt.(-700.0d0)) then
nz=1
ai=dcmplx(0.0d0,0.0d0)
return
endif
endif
endif
call zkr0(zta,fnu,scale,1_4,cy,nz)
else
if(scale) then
if(aa.le.(-664.0d0)) then
aa=-aa+0.25d0*alaz
iflag=1
sfac=1.0d-16
if(aa.gt.700.0d0) goto 9
endif
endif
mr=1
if(zi.lt.0.0d0) mr=-1
call zkrca(zta,fnu,scale,mr,1_4,cy,nnn)
if(nnn.ge.0) then
nz=nz+nnn
goto 1
else
goto 9
endif
1 s1=cy(1)*dcmplx(coef,0.0d0)
if(iflag.ne.0) then
s1=s1*dcmplx(sfac,0.0d0)
if(deriv) then
s1=-s1*z
else
s1=s1*csq
endif
ai=s1*dcmplx(1.0d0/sfac,0.0d0)
elseif(deriv) then
ai=-z*s1
else
ai=csq*s1
endif
endif
else
s1=cone
s2=cone
if(az.lt.1.0d-16) then
aa=1.0d-304
s1=dcmplx(0.0d0,0.0d0)
if(deriv) then
ai=-dcmplx(c2,0.0d0)
aa=sqrt(aa)
if(az.gt.aa) s1=z*z*dcmplx(0.5d0,0.0d0)
ai=ai+s1*dcmplx(c1,0.0d0)
else
if(az.gt.aa) s1=dcmplx(c2,0.0d0)*z
ai=dcmplx(c1,0.0d0)-s1
endif
else
aa=az*az
if(aa.ge.1.0d-16/az) then
trm1=cone
trm2=cone
atrm=1.0d0
z3=z*z*z
az3=az*aa
if(deriv) then
ak=3.0d0
bk=1.0d0
ck=3.0d0
d1=15.0d0
d2=3.0d0
ad=3.0d0
ak=33.0d0
bk=21.0d0
else
ak=2.0d0
bk=3.0d0
ck=4.0d0
d1=6.0d0
d2=12.0d0
ad=6.0d0
ak=24.0d0
bk=30.0d0
endif
z3r=dble(z3)
z3i=dimag(z3)
do 2 k=1,25
trm1=trm1*dcmplx(z3r/d1,z3i/d1)
s1=s1+trm1
trm2=trm2*dcmplx(z3r/d2,z3i/d2)
s2=s2+trm2
atrm=atrm*az3/ad
d1=d1+ak
d2=d2+bk
ad=min(d1,d2)
if(atrm.lt.1.0d-16*ad) then
goto 3
else
ak=ak+18.0d0
bk=bk+18.0d0
endif
2 continue
endif
3 if(deriv) then
ai=-s2*dcmplx(c2,0.0d0)
if(az.gt.1.0d-16) ai=ai+z*z*s1*dcmplx(c1/2.0d0,0.0d0)
else
ai=s1*dcmplx(c1,0.0d0)-z*s2*dcmplx(c2,0.0d0)
endif
if(scale) then
zta=z*sqrt(z)*dcmplx(tth,0.0d0)
ifl=1
ai=ai*zexp(zta,ifl)
endif
endif
endif
9 nz=0
ier=1
end
subroutine zir0(z,fnu,scale,n,cy,nz)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,cy(n),czero,cw(2)
Logical scale
Data czero/(0.0d0,0.0d0)/
nz=0
az=abs(z)
nn=n
dfnu=fnu+dble(n-1)
if((az.gt.2.0d0).and.(az*az*0.25d0.gt.dfnu+1.0d0)) goto 20
call zirp(z,fnu,scale,nn,cy,nw)
inw=abs(nw)
nz=nz+inw
nn=nn-inw
if(nn.eq.0) return
if(nw.ge.0) return
dfnu=fnu+dble(nn-1)
20 if(az.ge.21.0d0) then
if((dfnu.gt.1.0d0).and.(az+az.lt.dfnu*dfnu)) goto 40
call zirua0(z,fnu,scale,nn,cy,nw)
if(nw.lt.0) goto 120
return
else
if(dfnu.le.1.0d0) goto 100
endif
40 call zikrp1(z,fnu,scale,1_4,nn,cy,nw)
if(nw.lt.0) then
goto 120
else
nz=nz+nw
nn=nn-nw
if(nn.eq.0) return
dfnu=fnu+dble(nn-1)
if((dfnu.le.82.0d0).and.(az.le.82.0d0)) goto 60
nui=int(82.0d0-dfnu)+1
nui=max(nui,0)
call zirua(z,fnu,scale,nn,cy,nw,nui,nlast)
if(nw.lt.0) goto 120
nz=nz+nw
if(nlast.eq.0) return
nn=nlast
60 if(az.gt.21.0d0) then
call zikrp1(z,fnu,scale,2_4,2_4,cw,nw)
if(nw.lt.0) then
nz=nn
do 80 i=1,nn
cy(i)=czero
80 continue
return
elseif(nw.gt.0) then
goto 120
else
call zirw(z,fnu,scale,nn,cy,nw,cw)
if(nw.lt.0) goto 120
return
endif
endif
endif
100 call zirm(z,fnu,scale,nn,cy,nw)
if(nw.ge.0) return
120 nz=-1
if(nw.eq.(-2)) nz=-2
if(nw.eq.(-3)) nz=-3
end
subroutine zirw(zr,fnu,scale,n,y,nz,cw)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) zr,cw(2),y(n),c1,c2,cinu,cscl,ct,rct,st
Logical scale
nz=0
call zkr0(zr,fnu,scale,2_4,cw,nw)
if(nw.ne.0) then
nz=-1
if(nw.eq.(-2)) nz=-2
if(nw.eq.(-3)) nz=-3
else
call zirbr(zr,fnu,n,y)
cinu=dcmplx(1.0d0,0.0d0)
if(scale) then
yy=dimag(zr)
s1=cos(yy)
s2=sin(yy)
cinu=dcmplx(s1,s2)
endif
acw=abs(cw(2))
ascle=1.0d-288
cscl=dcmplx(1.0d0,0.0d0)
if(acw.gt.ascle) then
ascle=1.0d0/ascle
if(acw.ge.ascle) cscl=dcmplx(1.0d-16,0.0d0)
else
cscl=dcmplx(1.0d16,0.0d0)
endif
c1=cw(1)*cscl
c2=cw(2)*cscl
st=y(1)
ct=zr*(c2+st*c1)
act=abs(ct)
rct=dcmplx(1.0d0/act,0.0d0)
ct=dconjg(ct)*rct
cinu=cinu*rct*ct
y(1)=cinu*cscl
if(n.ne.1) then
do 1 i=2,n
cinu=st*cinu
st=y(i)
y(i)=cinu*cscl
1 continue
endif
endif
end
subroutine zikrp1(z,fnu,scale,ikflg,n,y,nuf)
implicit Real(8) (a-h,o-z)
implicit Integer(4) (i-n)
Complex(8) z,y(n),arg,asum,bsum,cz,czero,phi,sum,zb,zeta1,zeta2,
* zn,zr,cwrk(16)
Logical scale
Data czero/(0.0d0,0.0d0)/
Data aic/1.265512123484645396d+00/
nuf=0
nn=n
x=dble(z)
zr=z
if(x.lt.0.0d0) zr=-z
zb=zr
yy=dimag(zr)
ax=abs(x)*1.7321d0
ay=abs(yy)
iform=1
if(ay.gt.ax) iform=2
gnu=max(fnu,1.0d0)
if(ikflg.ne.1) then
fnn=dble(nn)
gnn=fnu+fnn-1.0d0
gnu=max(gnn,fnn)
endif
if(iform.eq.2) then
zn=-zr*dcmplx(0.0d0,1.0d0)
if(yy.le.0.0d0) zn=dconjg(-zn)
call zjhrua(zn,gnu,1_4,phi,arg,zeta1,zeta2,asum,bsum)
cz=-zeta1+zeta2
aarg=abs(arg)
else
init=0
call zikrp2(zr,gnu,ikflg,1_4,init,phi,zeta1,zeta2,sum,cwrk)
cz=-zeta1+zeta2
endif
if(scale) cz=cz-zb
if(ikflg.eq.2) cz=-cz
aphi=abs(phi)
rcz=dble(cz)
if(rcz.le.700.0d0) then
if(rcz.lt.664.0d0) then
if(rcz.ge.(-700.0d0)) then