-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaalyrmod.f90
6591 lines (6067 loc) · 224 KB
/
aalyrmod.f90
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
! Copyright 2014, Aytac Alparslan
! This file is part of OpenMaXwell.
!
! OpenMaXwell is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
! OpenMaXwell is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
! You should have received a copy of the GNU General Public License
! along with OpenMaXwell. If not, see <http://www.gnu.org/licenses/>.
MODULE AALYR
USE CHBND
Integer(4), parameter :: mxlyr=9 ! maximum number of layers
complex*16 aaepsr(0:mxlyr) ! relative permittivity values for the layers exp(j{omega}t) is used
complex*16 aamur(0:mxlyr) ! relative permeability values for the layers exp(j{omega}t) is used
complex*16 aakz(0:mxlyr) ! wave numbers along the layers for a given krho: needed for the integrants
complex*16 aakk(0:mxlyr) ! wave numbers of different layers when kgamma.eq.0 (when kgamma.ne.0 aakk=sqrt(aakkgamma**2-kgamma**2))
complex*16 aakkgamma(0:mxlyr) ! wave numbers of different layers when kgamma.ne.0
complex*16 k00 ! wave number in air for the given frequency
complex*16 aadint ! the magnitude of the half sin function during the integration
complex*16 aaxte(10) ! te mode surface wave poles in the complex krho plane
complex*16 aaxtm(10) ! tm mode surface wave poles in the complex krho plane
complex*16 aaxdum(10) ! dummy needed for iHEK=2
complex*16 kgamma ! the out of screen component of the wavevector of monopoles (for the eigenvalue analysis)
real*8 aadd(0:mxlyr) ! (INPUT)thickness values of the layers (between layer 1 and layer aanoflyr-1)
real*8 aah !(INPUT) elevation of the source from the layer down (aaslyr-1)
real*8 aaz !the y component of the field point for internal calculations
real*8 aax !the x component of the field point for internal calculations
real*8 aay !the z component of the field point for internal calculations
real*8 aaxi !the x component of the field point for internal calculations (imaginary part)
real*8 aayi !the z component of the field point for internal calculations (imaginary part)
real*8 aazi !the y component of the field point for internal calculations (imaginary part)
complex*16 aaxc ! the complex location of the source point (x- component)
complex*16 aayc ! the complex location of the source point (z- component)
complex*16 aazc ! the complex location of the source point (y- component)
real*8 aarho ! the rho component of the field point for internal calculations (x in 2D, rho in 3D)
real*8 aarhoi ! the rho component of the field point for internal calculations (x in 2D, rho in 3D) (imaginary part)
complex*16 aarhoc ! the complex location of the source point (x in 2D, rho in 3D) (rho- component)
real*8 aakmax ! maximum value of (real part) of the wave numbers of the different layers: needed for surface wave pole search
real*8 aakrhomax ! the value after which the integration continues as a integrate_and_sum method
Integer(4) aacpflag !complex path flag (needed for complex origin green functions)
real*8 aaepsrel ! relative error criteria for the integrator taken to 1d-6 as default
real*8 aafreq_norm ! frequency value for the calculation in GHz
Integer(4) aanoflyr ! (INPUT) number of layers
Integer(4) aaolyr ! observation layer: automatically calculted inside and used for internal calculations (internal)
Integer(4) aakey ! order of integration: taken 6 as the default value
Integer(4) aante ! number of te mode surface wave poles: needed for residue calcultions
Integer(4) aantm ! number of tm mode surface wave poles: needed for residue calcultions
Integer(4) aandum ! dummy needed for iHEK=2
Integer(4) aaslyr ! source layer number (internal)
Integer(4) source_lyr ! (INPUT) source layer number
Integer(4) swpflag ! internal constant to see if the swps are on the real axis or not
Integer(4) peccheck(2) ! (INPUT) if pecheck(1)=1(2) lowermost layer is PEC(PMC); if pecheck(2)=1(2) uppermost layer is PEC(PMC)
save
contains
subroutine getTwodlyrAux(ys)
! auxiliary routine that evaluates auxiliary parameters from OpenMaXwell boundary data
implicit none
Integer(4) l
Real(8) ys ! y component of the source (monopole) in global coordinates
do l=1,aanoflyr-2 ! compute layer heights from boundary data: domain l is between boundary l and l+1
aadd(l)=tBndEdg(tBnd(l+1)%iEdgeOffset+1)%y-tBndEdg(tBnd(l)%iEdgeOffset+1)%y
end do
source_lyr=0
do l=1,aanoflyr-1 ! find source layer and distance aah of source from its lower boundary
if(ys.lt.tBndEdg(tBnd(l)%iEdgeOffset+1)%y) then ! source layer found
source_lyr=l
aah=ys-tBndEdg(tBnd(l-1)%iEdgeOffset+1)%y
Exit
end if
end do
if(source_lyr.lt.1) then ! source lyaer not found, must be top layer
source_lyr=aanoflyr
aah=ys-tBndEdg(tBnd(aanoflyr-1)%iEdgeOffset+1)%y
end if
end subroutine getTwodlyrAux
subroutine twodlyr(kEx,kPa,maxPar,nP,iHEK,ri,rimag,kmaxmult,A,obs_lyr,gamma_re,gamma_im)
implicit none
Integer(4) kEx,kPa,nP,mPa,obs_lyr
Integer(2) maxPar,iHEK
complex*16 aaA(10),A(10,nParN)
real*8 ri(3),r(3),d,w,kmaxmult,rimag(3),gamma_re,gamma_im
if((kEx.lt.0).or.(kEx.gt.nExp).or.(maxPar.lt.1)) return
r=ri
d=r3Vec_Length(r)
w=1.0d0/Dble(kw0*fcFld)
aadint=0.0
if (kmaxmult.lt.0.0) then
aadint=floor(dlog10(dabs(kmaxmult)))
aadint=10**aadint
kmaxmult=dabs(kmaxmult)/aadint
endif
nP=0
mPa=kPa+maxPar
if(lInitSurfWaves) then ! lInitSurfWaves is a logical variable of OpenMaXwell, true at the beginning
swpflag=0
lInitSurfWaves=.false.
end if
if (cdabs(dcmplx(gamma_re,-gamma_im)).gt.1e-6) then ! If there is kgamma component, then continue to
!!!!!!!!!!!!!!!!!!!!!
if ((kPa.lt.mPa).and.(iHEK.eq.0)) then !Ez mode
call twodlyrbase_kgamma(0,r,rimag,kmaxmult,aaA,obs_lyr,gamma_re,gamma_im)
kPa=kPa+1
nP=nP+1
A(3,kPa)=A(3,kPa)-conjg(aaA(3))
A(4,kPa)=A(4,kPa)-conjg(aaA(4))
A(5,kPa)=A(5,kPa)-conjg(aaA(5))
A(1,kPa)=A(1,kPa)-conjg(aaA(1))
A(2,kPa)=A(2,kPa)-conjg(aaA(2))
A(6,kPa)=A(6,kPa)-conjg(aaA(6))
A(9,kPa)=A(9,kPa)+aaA(9)
elseif ((kPa.lt.mPa).and.(iHEK.eq.1)) then ! Hz mode
kPa=kPa+1
nP=nP+1
call twodlyrbase_kgamma(1,r,rimag,kmaxmult,aaA,obs_lyr,gamma_re,gamma_im)
A(1,kPa)=A(1,kPa)+conjg(aaA(1))*mue0/eps0
A(2,kPa)=A(2,kPa)+conjg(aaA(2))*mue0/eps0
A(6,kPa)=A(6,kPa)-conjg(aaA(6))
A(3,kPa)=A(3,kPa)+conjg(aaA(3))*mue0/eps0
A(4,kPa)=A(4,kPa)-conjg(aaA(4))
A(5,kPa)=A(5,kPa)-conjg(aaA(5))
A(9,kPa)=A(9,kPa)+aaA(9)
elseif ((kPa.lt.mPa).and.(iHEK.eq.2)) then ! hybrid mode
kPa=kPa+1
nP=nP+1
call twodlyrbase_kgamma(0,r,rimag,kmaxmult,aaA,obs_lyr,gamma_re,gamma_im)
A(3,kPa)=A(3,kPa)-conjg(aaA(3))
A(4,kPa)=A(4,kPa)-conjg(aaA(4))
A(5,kPa)=A(5,kPa)-conjg(aaA(5))
A(1,kPa)=A(1,kPa)-conjg(aaA(1))
A(2,kPa)=A(2,kPa)-conjg(aaA(2))
A(6,kPa)=A(6,kPa)-conjg(aaA(6))
A(9,kPa)=A(9,kPa)+aaA(9)
kPa=kPa+1
nP=nP+1
aaxdum=aaxte !interchange te and tm-mode swps
aaxte=aaxtm
aaxtm=aaxdum
aandum=aante
aante=aantm
aantm=aandum
call twodlyrbase_kgamma(1,r,rimag,kmaxmult,aaA,obs_lyr,gamma_re,gamma_im)
A(1,kPa)=A(1,kPa)+conjg(aaA(1))*mue0/eps0
A(2,kPa)=A(2,kPa)+conjg(aaA(2))*mue0/eps0
A(6,kPa)=A(6,kPa)-conjg(aaA(6))
A(3,kPa)=A(3,kPa)+conjg(aaA(3))*mue0/eps0
A(4,kPa)=A(4,kPa)-conjg(aaA(4))
A(5,kPa)=A(5,kPa)-conjg(aaA(5))
A(9,kPa)=A(9,kPa)+aaA(9)
aaxdum=aaxte !interchange te and tm-mode swps
aaxte=aaxtm
aaxtm=aaxdum
aandum=aante
aante=aantm
aantm=aandum
endif
!!!!!!!!!!!!!!!!!!!!!
else
if ((kPa.lt.mPa).and.(iHEK.eq.0)) then !Ez mode
call twodlyrbase(0,r,rimag,kmaxmult,aaA,obs_lyr)
kPa=kPa+1
nP=nP+1
A(3,kPa)=A(3,kPa)-conjg(aaA(3))
A(4,kPa)=A(4,kPa)-conjg(aaA(4))
A(5,kPa)=A(5,kPa)-conjg(aaA(5))
A(1,kPa)=A(1,kPa)-conjg(aaA(1))
A(2,kPa)=A(2,kPa)-conjg(aaA(2))
A(6,kPa)=A(6,kPa)-conjg(aaA(6))
A(9,kPa)=A(9,kPa)+aaA(9)
elseif ((kPa.lt.mPa).and.(iHEK.eq.1)) then ! Hz mode
kPa=kPa+1
nP=nP+1
call twodlyrbase(1,r,rimag,kmaxmult,aaA,obs_lyr)
A(1,kPa)=A(1,kPa)+conjg(aaA(1))
A(2,kPa)=A(2,kPa)+conjg(aaA(2))
A(6,kPa)=A(6,kPa)+conjg(aaA(6))
A(3,kPa)=A(3,kPa)+conjg(aaA(3))
A(4,kPa)=A(4,kPa)+conjg(aaA(4))
A(5,kPa)=A(5,kPa)+conjg(aaA(5))
A(9,kPa)=A(9,kPa)+aaA(9)
elseif ((kPa.lt.mPa).and.(iHEK.eq.2)) then ! hybrid mode
kPa=kPa+1
nP=nP+1
call twodlyrbase(0,r,rimag,kmaxmult,aaA,obs_lyr)
A(3,kPa)=A(3,kPa)-conjg(aaA(3))
A(4,kPa)=A(4,kPa)-conjg(aaA(4))
A(5,kPa)=A(5,kPa)-conjg(aaA(5))
A(1,kPa)=A(1,kPa)-conjg(aaA(1))
A(2,kPa)=A(2,kPa)-conjg(aaA(2))
A(6,kPa)=A(6,kPa)-conjg(aaA(6))
A(9,kPa)=A(9,kPa)+aaA(9)
kPa=kPa+1
nP=nP+1
aaxdum=aaxte !interchange te and tm-mode swps
aaxte=aaxtm
aaxtm=aaxdum
aandum=aante
aante=aantm
aantm=aandum
call twodlyrbase(1,r,rimag,kmaxmult,aaA,obs_lyr)
A(1,kPa)=A(1,kPa)+conjg(aaA(1))
A(2,kPa)=A(2,kPa)+conjg(aaA(2))
A(6,kPa)=A(6,kPa)+conjg(aaA(6))
A(3,kPa)=A(3,kPa)+conjg(aaA(3))
A(4,kPa)=A(4,kPa)+conjg(aaA(4))
A(5,kPa)=A(5,kPa)+conjg(aaA(5))
A(9,kPa)=A(9,kPa)+aaA(9)
aaxdum=aaxte !interchange te and tm-mode swps
aaxte=aaxtm
aaxtm=aaxdum
aandum=aante
aante=aantm
aantm=aandum
endif
endif
endsubroutine twodlyr
subroutine threedlyr(kEx,kPa,maxPar,nP,iHEK,iHVK,ri,rimag,kmaxmult,A,obs_lyr)
implicit none
Integer(4) kEx,kPa, nP, mPa, obs_lyr
Integer(2) maxPar,iHEK,iHVK
complex*16 aaAh(10,3),A(10,nParN)
real*8 ri(3),r(3),d,w,kmaxmult,rimag(3)
if((kEx.lt.0).or.(kEx.gt.nExp).or.(maxPar.lt.1)) return
r=ri
d=r3Vec_Length(r)
w=1.0d0/Dble(kw0*fcFld)
aadint=0.0
if (kmaxmult.lt.0.0) then
aadint=floor(dlog10(dabs(kmaxmult)))
aadint=10**aadint
kmaxmult=dabs(kmaxmult)/aadint
endif
! The results are generated by the coordinate system used in OpenMaXwell
nP=0
mPa=kPa+maxPar
if ((kPa.lt.mPa).and.(iHEK.eq.0)) then !electric dipole mode
kPa=kPa+1
nP=nP+1
call threedlyrbasehor(0,r,rimag,kmaxmult,aaAh,obs_lyr,iHVK)
A(1,kPa)=A(1,kPa)-conjg(aaAh(1,1)) ! Horizontal dipole 1
A(2,kPa)=A(2,kPa)-conjg(aaAh(3,1))
A(3,kPa)=A(3,kPa)+conjg(aaAh(2,1))
A(4,kPa)=A(4,kPa)-conjg(aaAh(4,1))
A(5,kPa)=A(5,kPa)-conjg(aaAh(6,1))
A(6,kPa)=A(6,kPa)+conjg(aaAh(5,1))
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)-conjg(aaAh(1,3)) ! Vertical dipole
A(2,kPa)=A(2,kPa)-conjg(aaAh(3,3))
A(3,kPa)=A(3,kPa)+conjg(aaAh(2,3))
A(4,kPa)=A(4,kPa)-conjg(aaAh(4,3))
A(5,kPa)=A(5,kPa)-conjg(aaAh(6,3))
A(6,kPa)=A(6,kPa)+conjg(aaAh(5,3))
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)+conjg(aaAh(1,2)) ! Horizontal dipole 2
A(2,kPa)=A(2,kPa)+conjg(aaAh(3,2))
A(3,kPa)=A(3,kPa)-conjg(aaAh(2,2))
A(4,kPa)=A(4,kPa)+conjg(aaAh(4,2))
A(5,kPa)=A(5,kPa)+conjg(aaAh(6,2))
A(6,kPa)=A(6,kPa)-conjg(aaAh(5,2))
elseif ((kPa.lt.mPa).and.(iHEK.eq.1)) then !magnetic dipole mode
kPa=kPa+1
nP=nP+1
call threedlyrbasehor(1,r,rimag,kmaxmult,aaAh,obs_lyr,iHVK)
A(1,kPa)=A(1,kPa)+conjg(aaAh(4,1)) !Horizontal dipole 1
A(2,kPa)=A(2,kPa)+conjg(aaAh(6,1))
A(3,kPa)=A(3,kPa)-conjg(aaAh(5,1))
A(4,kPa)=A(4,kPa)-conjg(aaAh(1,1)*eps0/mue0)
A(5,kPa)=A(5,kPa)-conjg(aaAh(3,1)*eps0/mue0)
A(6,kPa)=A(6,kPa)+conjg(aaAh(2,1)*eps0/mue0)
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)+conjg(aaAh(4,3)) !Vertical dipole
A(2,kPa)=A(2,kPa)+conjg(aaAh(6,3))
A(3,kPa)=A(3,kPa)-conjg(aaAh(5,3))
A(4,kPa)=A(4,kPa)-conjg(aaAh(1,3)*eps0/mue0)
A(5,kPa)=A(5,kPa)-conjg(aaAh(3,3)*eps0/mue0)
A(6,kPa)=A(6,kPa)+conjg(aaAh(2,3)*eps0/mue0)
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)-conjg(aaAh(4,2)) !Horizontal dipole 2
A(2,kPa)=A(2,kPa)-conjg(aaAh(6,2))
A(3,kPa)=A(3,kPa)+conjg(aaAh(5,2))
A(4,kPa)=A(4,kPa)+conjg(aaAh(1,2)*eps0/mue0)
A(5,kPa)=A(5,kPa)+conjg(aaAh(3,2)*eps0/mue0)
A(6,kPa)=A(6,kPa)-conjg(aaAh(2,2)*eps0/mue0)
elseif ((kPa.lt.mPa).and.(iHEK.eq.2)) then !hybrid dipole mode
kPa=kPa+1
nP=nP+1
call threedlyrbasehor(0,r,rimag,kmaxmult,aaAh,obs_lyr,iHVK)
A(1,kPa)=A(1,kPa)-conjg(aaAh(1,1)) ! Horizontal dipole 1
A(2,kPa)=A(2,kPa)-conjg(aaAh(3,1))
A(3,kPa)=A(3,kPa)+conjg(aaAh(2,1))
A(4,kPa)=A(4,kPa)-conjg(aaAh(4,1))
A(5,kPa)=A(5,kPa)-conjg(aaAh(6,1))
A(6,kPa)=A(6,kPa)+conjg(aaAh(5,1))
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)-conjg(aaAh(1,3)) ! Vertical dipole
A(2,kPa)=A(2,kPa)-conjg(aaAh(3,3))
A(3,kPa)=A(3,kPa)+conjg(aaAh(2,3))
A(4,kPa)=A(4,kPa)-conjg(aaAh(4,3))
A(5,kPa)=A(5,kPa)-conjg(aaAh(6,3))
A(6,kPa)=A(6,kPa)+conjg(aaAh(5,3))
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)+conjg(aaAh(1,2)) ! Horizontal dipole 2
A(2,kPa)=A(2,kPa)+conjg(aaAh(3,2))
A(3,kPa)=A(3,kPa)-conjg(aaAh(2,2))
A(4,kPa)=A(4,kPa)+conjg(aaAh(4,2))
A(5,kPa)=A(5,kPa)+conjg(aaAh(6,2))
A(6,kPa)=A(6,kPa)-conjg(aaAh(5,2))
kPa=kPa+1
nP=nP+1
call threedlyrbasehor(1,r,rimag,kmaxmult,aaAh,obs_lyr,iHVK)
A(1,kPa)=A(1,kPa)+conjg(aaAh(4,1)) !Horizontal dipole 1
A(2,kPa)=A(2,kPa)+conjg(aaAh(6,1))
A(3,kPa)=A(3,kPa)-conjg(aaAh(5,1))
A(4,kPa)=A(4,kPa)-conjg(aaAh(1,1)*eps0/mue0)
A(5,kPa)=A(5,kPa)-conjg(aaAh(3,1)*eps0/mue0)
A(6,kPa)=A(6,kPa)+conjg(aaAh(2,1)*eps0/mue0)
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)+conjg(aaAh(4,3)) !Vertical dipole
A(2,kPa)=A(2,kPa)+conjg(aaAh(6,3))
A(3,kPa)=A(3,kPa)-conjg(aaAh(5,3))
A(4,kPa)=A(4,kPa)-conjg(aaAh(1,3)*eps0/mue0)
A(5,kPa)=A(5,kPa)-conjg(aaAh(3,3)*eps0/mue0)
A(6,kPa)=A(6,kPa)+conjg(aaAh(2,3)*eps0/mue0)
kPa=kPa+1
nP=nP+1
A(1,kPa)=A(1,kPa)-conjg(aaAh(4,2)) !Horizontal dipole 2
A(2,kPa)=A(2,kPa)-conjg(aaAh(6,2))
A(3,kPa)=A(3,kPa)+conjg(aaAh(5,2))
A(4,kPa)=A(4,kPa)+conjg(aaAh(1,2)*eps0/mue0)
A(5,kPa)=A(5,kPa)+conjg(aaAh(3,2)*eps0/mue0)
A(6,kPa)=A(6,kPa)-conjg(aaAh(2,2)*eps0/mue0)
endif
endsubroutine threedlyr
subroutine threedlyrbasehor(aaiHEK,r,rimag,kmaxmult,aaA,obs_lyr,iHVK)
implicit none
complex*16 freq,caafreq_norm
Integer(4) reflag,aaiHEK,i
Integer(2) iHVK
real*8 xdata,ydata,kmaxmult,zdata
complex*16 dumm(0:mxlyr)
complex*16 aarr
real*8 rimag(3),r(3)
Integer(4) halfcyc
complex*16 aafcFld
Integer(4) obs_lyr
Integer(4) path_id1, path_id2, path_id3, path_id4
complex*16 aaA(10,3)
complex*16 integrator_res(15)
aaA=(0.0d0,0.0d0)
aafcFld=dreal(fcFld)-Ci*dabs((dimag(fcFld)))
aafreq_norm=dreal(aafcFld)/1e9
caafreq_norm=aafcFld/1e9
freq=aafcFld/aafreq_norm ! frequency to GHz
k00=2*pi*freq*dsqrt(eps0*mue0) ! wave number of freespace
aakmax=dreal(k00)**2
call geomnormer(r,obs_lyr)
rimag=rimag*aafreq_norm !normalize the imaginary origin values
xdata=r(1) ! x-information (field point)
zdata=r(2) ! y-information (field point)
ydata=-r(3) ! z-information (field point)
aaxi=rimag(1) ! x-information (field point)
aazi=rimag(2) ! y-information (field point)
aayi=-rimag(3) ! z-information (field point)
if (obs_lyr.lt.1) then
aaolyr=obslayer(zdata) ! observation layer calculation (comment if the obslayer will be given outsite)
endif
aakey=3 ! order of integration (default is 6)
if (aaiHEK.eq.1) then ! check if the polarization is TM if so interchange parameters
dumm=aaepsr
aaepsr=aamur
aamur=dumm
if (peccheck(1).eq.1) then
peccheck(1)=2
elseif (peccheck(1).eq.2) then
peccheck(1)=1
endif
if (peccheck(2).eq.2) then
peccheck(2)=1
elseif (peccheck(2).eq.1) then
peccheck(2)=2
endif
endif
reflag=0 !assume all the swps are purely real
!CALCULATE THE k VECTORS IN ALL OF THE LAYERS
do i=0,aanoflyr-1 !wavenumbers of each layer
if (i.eq.0) then
if (peccheck(1).eq.0) then
aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
else
aakk(i)=0.0
endif
elseif (i.eq.aanoflyr-1) then
if (peccheck(2).eq.0) then
aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
else
aakk(i)=0.0
endif
else
aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
endif
if (dimag(aakk(i)).lt.0.0) then
reflag=1 !the swps have imaginary part
endif
if ((dreal(aakk(i))**2).gt.aakmax) then
aakmax=dreal(aakk(i))**2 ! Find the maximum k vector
endif
enddo
aakmax=sqrt(aakmax)*kmaxmult
if (swpflag.eq.0) then ! if not run before, run it once
call swpoles(aaxte,aaxtm) ! determine the locations of surface wave poles
swpflag=1
endif
!! START THE MAIN CODE !!
aaz=zdata
aax=xdata
aay=ydata
if (dabs(aax).lt.1d-10) then
aax=(1d-10)*sign(1.0d0,aax)
endif
if (dabs(aay).lt.1d-10) then
aay=(1d-10)*sign(1.0d0,aay)
endif
aarhoc=cdsqrt((aax+Ci*aaxi)**2+(aay+Ci*aayi)**2)
if (dreal(aarhoc).lt.0.0) aarhoc=-aarhoc ! must have a positive real part because of the setting in the code
aarho=dreal(aarhoc)
aarhoi=dimag(aarhoc)
aarr=cdsqrt((aax+Ci*aaxi)**2+(aay+Ci*aayi)**2+(aaz+Ci*aazi)**2)
if (dreal(aarr).lt.0.0) aarr=-aarr ! must have a positive real part because of the setting in the code
aaxc=aax+Ci*aaxi
aayc=aay+Ci*aayi
aazc=aaz+Ci*aazi
if (dreal(aadint).gt.0.0) then
aadint=aadint*aakmax
else
aadint=aakmax*1d-3
endif
! integration of all the integrants
if ((dabs(aarhoi) .gt. 1d-8).or.(dabs(aazi).gt.1d-8)) then ! if there is some complex origin that effects the results
call path_chooser3d(path_id1,path_id2)
call path_chooser3d_opp(path_id3,path_id4)
halfcyc=31
call integrator3dc(halfcyc,integrator_res,path_id1,path_id2,path_id3,path_id4,iHVK) ! integration of all the integrants simultaneously by Gauss Kronrod
else ! if no complex origin is seen continue with the standart integrator
halfcyc=21
call integrator3d(halfcyc,integrator_res,iHVK)! integration of all the integrants simultaneously by Gauss Kronrod
endif
if (iHVK.ne.1) then
aaA(1,1)=-Ci*2*pi*freq*(aafreq_norm)*(integrator_res(1)+(integrator_res(2)/((2*pi*freq)**2))) ! Hor Exx
aaA(2,1)=integrator_res(3)*(aafreq_norm)/(Ci*2*pi*freq) ! Hor Eyx
aaA(3,1)=-Ci*2*pi*freq*(aafreq_norm)*(integrator_res(5)+integrator_res(4)/((2*pi*freq)**2)) ! Hor Ezx
aaA(4,1)=integrator_res(6)*aafreq_norm/aamur(aaolyr) !Hor Hxx
aaA(5,1)=aafreq_norm*(integrator_res(7)-integrator_res(8))/aamur(aaolyr) !Hor Hyx
aaA(6,1)=-integrator_res(9)*aafreq_norm/aamur(aaolyr)
aaA(1,2)=aaA(2,1) !Hor Exy
aaA(2,2)=-Ci*2*pi*freq*(aafreq_norm)*(integrator_res(1)+(integrator_res(14)/((2*pi*freq)**2))) ! Hor Eyy
aaA(3,2)=aaA(3,1)*aayc/aaxc !Hor Ezy
aaA(4,2)=-aafreq_norm*(integrator_res(7)-integrator_res(15))/aamur(aaolyr)
!aaA(4,2)=-aaA(5,1) !Hor Hxy (- times Hyx)
aaA(5,2)=-aaA(4,1) !Hor Hyy (- times Hxx)
aaA(6,2)=-aaA(6,1)*aaxc/aayc !Hor Hzy
if (aaslyr.eq.aaolyr) then !direct term inclusion
aaA(1,1)=aaA(1,1)+(aafreq_norm*(cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*(aakk(aaslyr)**2-Ci*aakk(aaslyr)/aarr-(1.0+(aaxc**2)*(aakk(aaslyr)**2))/(aarr**2)+(3*Ci*aakk(aaslyr)*aaxc**2)/(aarr**3)+(3*aaxc**2)/(aarr**4)))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr))
aaA(2,1)=aaA(2,1)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aayc*aaxc*(-aakk(aaslyr)**2+Ci*3*aakk(aaslyr)/aarr+3/(aarr**2))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr)*(aarr**2))
aaA(3,1)=aaA(3,1)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aaxc*aazc*(-aakk(aaslyr)**2+Ci*3*aakk(aaslyr)/aarr+3/(aarr**2))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr)*(aarr**2))
aaA(4,1)=aaA(4,1)+0.0
aaA(5,1)=aaA(5,1)-(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aazc*(Ci*aakk(aaslyr)/aarr+1/(aarr**2))/(4*pi)
aaA(6,1)=aaA(6,1)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aayc*(Ci*aakk(aaslyr)/aarr+1/(aarr**2))/(4*pi)
aaA(1,2)=aaA(1,2)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aayc*aaxc*(-aakk(aaslyr)**2+Ci*3*aakk(aaslyr)/aarr+3/(aarr**2))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr)*(aarr**2))
aaA(2,2)=aaA(2,2)+(aafreq_norm*(cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*(aakk(aaslyr)**2-Ci*aakk(aaslyr)/aarr-(1.0+(aayc**2)*(aakk(aaslyr)**2))/(aarr**2)+(3*Ci*aakk(aaslyr)*aayc**2)/(aarr**3)+(3*aayc**2)/(aarr**4)))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr))
aaA(3,2)=aaA(3,2)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aayc*aazc*(-aakk(aaslyr)**2+Ci*3*aakk(aaslyr)/aarr+3/(aarr**2))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr)*(aarr**2))
aaA(4,2)=aaA(4,2)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aazc*(Ci*aakk(aaslyr)/aarr+1/(aarr**2))/(4*pi)
aaA(5,2)=aaA(5,2)+0.0
aaA(6,2)=aaA(6,2)-(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aaxc*(Ci*aakk(aaslyr)/aarr+1/(aarr**2))/(4*pi)
endif
endif
if (iHVK.ne.0) then
aaA(1,3)=integrator_res(10)*(aafreq_norm)*aax/(Ci*2*pi*freq) !Exz
aaA(2,3)=aaA(1,3)*aay/aax ! Eyz
aaA(3,3)=-Ci*2*pi*freq*aafreq_norm*(integrator_res(11)+integrator_res(12)/((2*pi*freq)**2)) ! Ezz
aaA(4,3)=integrator_res(13)*aay*(aafreq_norm)/aamur(aaolyr) ! Hxz
aaA(5,3)=-aaA(4,3)*aax/aay ! Hyz
aaA(6,3)=0.0
if (aaslyr.eq.aaolyr) then !direct term inclusion
aaA(1,3)=aaA(1,3)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aaxc*aazc*(-aakk(aaslyr)**2+Ci*3*aakk(aaslyr)/aarr+3/(aarr**2))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr)*(aarr**2))
aaA(2,3)=aaA(2,3)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aayc*aazc*(-aakk(aaslyr)**2+Ci*3*aakk(aaslyr)/aarr+3/(aarr**2))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr)*(aarr**2))
aaA(3,3)=aaA(3,3)+(aafreq_norm*(cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*(aakk(aaslyr)**2-Ci*aakk(aaslyr)/aarr-(1.0+(aazc**2)*(aakk(aaslyr)**2))/(aarr**2)+(3*Ci*aakk(aaslyr)*aazc**2)/(aarr**3)+(3*aazc**2)/(aarr**4)))/(Ci*2*pi*freq*4*pi*eps0*aaepsr(aaslyr))
aaA(4,3)=aaA(4,3)-(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aayc*(Ci*aakk(aaslyr)/aarr+1/(aarr**2))/(4*pi)
aaA(5,3)=aaA(5,3)+(aafreq_norm*cdexp(-Ci*aakk(aaslyr)*aarr)/aarr)*aaxc*(Ci*aakk(aaslyr)/aarr+1/(aarr**2))/(4*pi)
aaA(6,3)=aaA(6,3)+0.0
endif
endif
call normer(aaA,r,aaiHEK,3)
rimag=rimag/aafreq_norm ! denomalize the imaginary parts of the origin
end subroutine threedlyrbasehor
subroutine twodlyrbase(aaiHEK,r,rimag,kmaxmult,aaA,obs_lyr)
implicit none
complex*16 freq
Integer(4) reflag,aaiHEK,i
real*8 xdata,ydata,kmaxmult
complex*16 dumm(0:mxlyr)
real*8 zconst
real*8 r(3),rimag(3)
Integer(4) halfcyc
complex*16 aafcFld
Integer(4) obs_lyr
Integer(4) path_id1, path_id2, path_id3, path_id4, path_id0
complex*16 aaA(10),ress(3), distx, distz, dist
Integer(4) idumy1,idumy2,idumy3,iErr
complex*16 cBes(0:20)
!!! CONSTANT INITIALIZATION
aaA=0.0
aafcFld=dreal(fcFld)-Ci*dabs((dimag(fcFld)))
aafreq_norm=dreal(aafcFld)/1e9
freq=aafcFld/aafreq_norm ! frequency to GHz
k00=2*pi*freq*dsqrt(eps0*mue0) ! wave number of freespace
aakmax=dreal(k00)**2-kgamma**2
call geomnormer(r,obs_lyr)
rimag=rimag*aafreq_norm ! normalize the imaginary origin values
kgamma=0.0
xdata=r(1) ! aax-information (field point)
ydata=r(2) ! y-information (field point)
if (obs_lyr.lt.1) then
aaolyr=obslayer(r(2)) ! observation layer calculation (comment if the obslayer will be given outsite)
endif
aakey=3 ! order of integration (default is 6)
if (aaiHEK.eq.1) then ! check if the polarization is TM if so interchange parameters
dumm=aaepsr
aaepsr=aamur
aamur=dumm
if (peccheck(1).eq.1) then
peccheck(1)=2
elseif (peccheck(1).eq.2) then
peccheck(1)=1
endif
if (peccheck(2).eq.2) then
peccheck(2)=1
elseif (peccheck(2).eq.1) then
peccheck(2)=2
endif
endif
reflag=0 !assume all the swps are purely real
!CALCULATE THE k VECTORS IN ALL OF THE LAYERS
if ((peccheck(1).eq.0).and.(peccheck(2).eq.0)) then
aaepsr=aaepsr-(1d-8)*Ci
elseif (peccheck(1).eq.0) then
aaepsr(1:aanoflyr)=aaepsr(1:aanoflyr)-(1d-8)*Ci
elseif (peccheck(2).eq.0) then
aaepsr(0:aanoflyr-1)=aaepsr(0:aanoflyr-1)-(1d-8)*Ci
endif
do i=0,aanoflyr-1 !wavenumbers of each layer
if (i.eq.0) then
if (peccheck(1).eq.0) then
aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
aakk(i)=sqrt(aakk(i)**2-kgamma**2)
else
aakk(i)=0.0
endif
elseif (i.eq.aanoflyr-1) then
if (peccheck(2).eq.0) then
aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
aakk(i)=sqrt(aakk(i)**2-kgamma**2)
else
aakk(i)=0.0
endif
else
aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
aakk(i)=sqrt(aakk(i)**2-kgamma**2)
endif
if (dreal(aakk(i)).lt.0.0) then
reflag=1 !the swps have imaginary part
aakk(i)=-aakk(i)
else
reflag=1
endif
if ((dreal(aakk(i))**2).gt.aakmax) then
aakmax=dreal(aakk(i))**2 ! Find the maximum k vector
endif
enddo
aakmax=sqrt(aakmax)*kmaxmult
if (swpflag.eq.0) then ! if not run before, run it once
call swpoles(aaxte,aaxtm) ! determine the locations of surface wave poles
swpflag=1
endif
!Start the main code
zconst=ydata
aaz=zconst
aazi=rimag(2)
aarho=xdata
aarhoi=rimag(1)
aarhoc=aarho+Ci*aarhoi
aazc=aaz+Ci*aazi
if (dreal(aadint).gt.0.0) then
aadint=aadint*aakmax
else
aadint=aakmax*1d-6
endif
if ((dabs(aarhoi) .gt. 1d-8).or.(dabs(aazi).gt.1d-8)) then ! if there is some complex origin
! determine the paths according to the causality thm.
call path_chooser(path_id1,path_id2) ! find the paths for the out-going waves
call path_chooser_opp(path_id3,path_id4) ! find the paths for the in-coming waves
path_id0=-1
halfcyc=31 ! the number of partial integrations for the aitken algorithm
ress=0.0
call integrator2dc(halfcyc,ress,path_id0,path_id1,path_id2,path_id3,path_id4)
else
halfcyc=21
ress=0.0
call integrator2d(halfcyc,ress)
endif
if (aaiHEK.eq.0) then
aaA(3)=-Ci*freq*2*pi*ress(1)
aaA(5)=-ress(2)/(mue0*aamur(aaolyr)) !
aaA(4)=ress(3)/(mue0*aamur(aaolyr)) !
if (aaslyr.eq.aaolyr) then !direct term inclusion
distx=dcmplx(aarho,aarhoi)
distz=dcmplx(aaz,aazi)
dist=cdsqrt(distx**2+distz**2) !complex distance
if (dreal(dist).lt.0.0) dist=-dist ! the real part of the distance must be positive
if (dimag(aakk(aaslyr)).gt.0.0) then
dist=-dist*aakk(aaslyr) ! argument of the hankel function
else
dist=dist*aakk(aaslyr) ! argument of the hankel function
endif
idumy1=2
idumy2=20
idumy3=14
call ch2(dist,cBes(0),idumy1,idumy2,idumy3,ierr)
if(ierr.gt.0) cBes=(0.0d0,0.0d0)
if((ierr.ne.0).and.lDispWarn) then
write(*,*) 'WARNING: Error',ierr,' in Bessel(',dist,')'
lDispWarn=.false.
end if
aaA(5)=aaA(5)-(Ci*aakk(aaslyr)*aakk(aaslyr)*distx*cBes(1))/(4*dist)
aaA(4)=aaA(4)+(Ci*aakk(aaslyr)*aakk(aaslyr)*distz*cBes(1))/(4*dist)
aaA(3)=aaA(3)-(freq*aamur(aaslyr)*mue0*pi*cBes(0))/2
endif
aaA(5)=aaA(5)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
aaA(4)=aaA(4)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
elseif (aaiHEK.eq.1) then
!Warning: Here epsilon and mu values are interchanged to convert from TE to TM. (by geomnormer)
aaA(6)=Ci*freq*2*pi*ress(1)*eps0/mue0 !Hzz
aaA(2)=-ress(2)/(mue0*aamur(aaolyr)) !
aaA(1)=ress(3)/(mue0*aamur(aaolyr)) !
if (aaslyr.eq.aaolyr) then !direct term inclusion
distx=dcmplx(aarho,aarhoi)
distz=dcmplx(aaz,aazi)
dist=cdsqrt(distx**2+distz**2) !complex distance
if (dreal(dist).lt.0.0) dist=-dist ! the real part of the distance must be positive
if (dimag(aakk(aaslyr)).gt.0.0) then
dist=-dist*aakk(aaslyr) ! argument of the hankel function
else
dist=dist*aakk(aaslyr) ! argument of the hankel function
endif
idumy1=2
idumy2=20
idumy3=14
call ch2(dist,cBes(0),idumy1,idumy2,idumy3,ierr)
if(ierr.gt.0) cBes=(0.0d0,0.0d0)
if((ierr.ne.0).and.lDispWarn) then
write(*,*) 'WARNING: Error',ierr,' in Bessel(',dist,')'
lDispWarn=.false.
end if
aaA(2)=aaA(2)-(Ci*aakk(aaslyr)*aakk(aaslyr)*distx*cBes(1))/(4*dist)
aaA(1)=aaA(1)+(Ci*aakk(aaslyr)*aakk(aaslyr)*distz*cBes(1))/(4*dist)
aaA(6)=aaA(6)+(freq*aamur(aaslyr)*eps0*pi*cBes(0))/2
endif
aaA(2)=aaA(2)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
aaA(1)=aaA(1)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
endif
call normer(aaA,r,aaiHEK,1)
rimag=rimag/aafreq_norm
endsubroutine twodlyrbase
!!!!!!!!!!!!!
!!subroutine twodlyrbase_kgamma(aaiHEK,r,rimag,kmaxmult,aaA,obs_lyr,gamma_re,gamma_im)
!!implicit none
!!complex*16 freq
!!Integer(4) reflag,aaiHEK,i
!!real*8 xdata,ydata,kmaxmult,gamma_re,gamma_im
!!complex*16 dumm(0:mxlyr)
!!real*8 zconst
!!real*8 r(3),rimag(3)
!!Integer(4) halfcyc
!!complex*16 aafcFld, kkphase(0:mxlyr)
!!Integer(4) obs_lyr
!!Integer(4) path_id1, path_id2, path_id3, path_id4, path_id0
!!complex*16 aaA(10),ress(9), distx, distz, dist
!!Integer(4) idumy1,idumy2,idumy3,iErr
!!complex*16 cBes(0:20)
!!
!!!!! CONSTANT INITIALIZATION
!!aaA=0.0
!!aafcFld=dreal(fcFld)-Ci*dabs((dimag(fcFld)))
!!aafreq_norm=dreal(aafcFld)/1e9
!!freq=aafcFld/aafreq_norm ! frequency to GHz
!!k00=2*pi*freq*dsqrt(eps0*mue0) ! wave number of freespace
!!kgamma=k00*dcmplx(gamma_re,-gamma_im) ! causality change for exp(-iwt)
!!aakmax=dreal(k00)**2-kgamma**2
!!call geomnormer(r,obs_lyr)
!!rimag=rimag*aafreq_norm ! normalize the imaginary origin values
!!
!!xdata=r(1) ! aax-information (field point)
!!ydata=r(2) ! y-information (field point)
!!
!!if (obs_lyr.lt.1) then
!! aaolyr=obslayer(r(2)) ! observation layer calculation (comment if the obslayer will be given outsite)
!!endif
!!aakey=3 ! order of integration (default is 6)
!!
!!if (aaiHEK.eq.1) then ! check if the polarization is TM if so interchange parameters
!! dumm=aaepsr
!! aaepsr=aamur
!! aamur=dumm
!! if (peccheck(1).eq.1) then
!! peccheck(1)=2
!! elseif (peccheck(1).eq.2) then
!! peccheck(1)=1
!! endif
!! if (peccheck(2).eq.2) then
!! peccheck(2)=1
!! elseif (peccheck(2).eq.1) then
!! peccheck(2)=2
!! endif
!!endif
!!
!!reflag=0 !assume all the swps are purely real
!!!CALCULATE THE k VECTORS IN ALL OF THE LAYERS
!!if ((peccheck(1).eq.0).and.(peccheck(2).eq.0)) then
!! aaepsr=aaepsr-(1d-8)*Ci
!!elseif (peccheck(1).eq.0) then
!! aaepsr(1:aanoflyr)=aaepsr(1:aanoflyr)-(1d-8)*Ci
!!elseif (peccheck(2).eq.0) then
!! aaepsr(0:aanoflyr-1)=aaepsr(0:aanoflyr-1)-(1d-8)*Ci
!!endif
!!
!!do i=0,aanoflyr-1 !wavenumbers of each layer
!! if (i.eq.0) then
!! if (peccheck(1).eq.0) then
!! aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
!! aakk(i)=sqrt(aakk(i)**2-kgamma**2)
!! kkphase(i)=aakk(i)/cdabs(aakk(i))
!! else
!! aakk(i)=0.0
!! endif
!! elseif (i.eq.aanoflyr-1) then
!! if (peccheck(2).eq.0) then
!! aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
!! aakk(i)=sqrt(aakk(i)**2-kgamma**2)
!! kkphase(i)=aakk(i)/cdabs(aakk(i))
!! else
!! aakk(i)=0.0
!! endif
!! else
!! aakk(i)=k00*sqrt(aaepsr(i)*aamur(i)) ! aakk(i):wavenumber of ith layer
!! aakk(i)=sqrt(aakk(i)**2-kgamma**2)
!! kkphase(i)=aakk(i)/cdabs(aakk(i))
!! endif
!! if (dreal(aakk(i)).lt.0.0) then
!! reflag=1 !the swps have imaginary part
!! aakk(i)=-aakk(i)
!! else
!! reflag=1
!! endif
!! if ((dreal(aakk(i))**2).gt.aakmax) then
!! aakmax=dreal(aakk(i))**2 ! Find the maximum k vector
!! endif
!!enddo
!!aakmax=sqrt(aakmax)*kmaxmult
!!
!!zconst=ydata
!!aaz=zconst
!!aazi=rimag(2)
!!aarho=xdata
!!aarhoi=rimag(1)
!!aarhoc=aarho+Ci*aarhoi
!!aazc=aaz+Ci*aazi
!!
!!aadint=aakmax*1d-9
!!
!!if ((dabs(aarhoi) .gt. 1d-8).or.(dabs(aazi).gt.1d-8)) then ! if there is some complex origin
!! ! determine the paths according to the causality thm.
!! call path_chooser(path_id1,path_id2) ! find the paths for the out-going waves
!! call path_chooser_opp(path_id3,path_id4) ! find the paths for the in-coming waves
!!! path_id0=-1
!!! halfcyc=31 ! the number of partial integrations for the aitken algorithm
!!! ress=0.0
!!! call integrator2dc_kgamma(halfcyc,ress,path_id0,path_id1,path_id2,path_id3,path_id4)
!!else
!! halfcyc=21
!! ress=0.0
!!! call integrator2d_kgamma(halfcyc,ress)
!!endif
!!
!!if (aaiHEK.eq.0) then
!!! aaA(1)=ress(3)*(aafreq_norm)/(Ci*2*pi*freq)
!!! aaA(2)=-Ci*2*pi*freq*(aafreq_norm)*(ress(5)+ress(4)/((2*pi*freq)**2))
!!! aaA(6)=ress(6)*aafreq_norm/(mue0*aamur(aaolyr))
!!! aaA(3)=-Ci*freq*2*pi*ress(1)
!!! aaA(5)=-ress(9)/(mue0*aamur(aaolyr)) !
!!! aaA(4)=ress(7)/(mue0*aamur(aaolyr)) !
!!!aaA(1)=ress(2)
!!!aaA(2)=ress(3)
!!!aaA(3)=ress(4)
!!!aaA(4)=ress(5)
!!!aaA(5)=ress(6)
!!!aaA(6)=ress(9)
!!
!!
!!! if (aaslyr.eq.aaolyr) then !direct term inclusion
!! distx=dcmplx(aarho,aarhoi)
!! distz=dcmplx(aaz,aazi)
!! dist=cdsqrt(distx**2+distz**2) !complex distance
!! if (dreal(dist).lt.0.0) dist=-dist ! the real part of the distance must be positive
!! if (dimag(aakk(aaslyr)).gt.0.0) then
!! dist=-dist*aakk(aaslyr) ! argument of the hankel function
!! else
!! dist=dist*aakk(aaslyr) ! argument of the hankel function
!! endif
!! idumy1=2
!! idumy2=20
!! idumy3=14
!! call ch2(dist,cBes(0),idumy1,idumy2,idumy3,ierr)
!! if(ierr.gt.0) cBes=(0.0d0,0.0d0)
!! if((ierr.ne.0).and.lDispWarn) then
!! write(*,*) 'WARNING: Error',ierr,' in Bessel(',dist,')'
!! lDispWarn=.false.
!! end if
!! aaA(3)=-0.5*pi*freq*cBes(0)*(mue0*aamur(aaslyr)-(kgamma**2/(((2*aafreq_norm*pi*freq)**2)*eps0*aaepsr(aaslyr))))
!! aaA(2)=(1/(Ci*8*pi*freq*dist*eps0*aaepsr(aaslyr)))*kgamma*aakk(aaslyr)*aakk(aaslyr)*distz*cBes(1)
!! aaA(1)=(1/(Ci*8*pi*freq*dist*eps0*aaepsr(aaslyr)))*kgamma*aakk(aaslyr)*aakk(aaslyr)*distx*cBes(1)
!! aaA(6)=0.0
!! aaA(5)=(1/(4*Ci*dist))*aakk(aaslyr)*distx*cBes(1)*aakk(aaslyr)
!! aaA(4)=-(1/(4*Ci*dist))*aakk(aaslyr)*distz*cBes(1)*aakk(aaslyr)
!!! aaA(5)=aaA(5)-(Ci*aakk(aaslyr)*aakk(aaslyr)*distx*cBes(1))/(4*dist)
!!! aaA(4)=aaA(4)+(Ci*aakk(aaslyr)*aakk(aaslyr)*distz*cBes(1))/(4*dist)
!!! aaA(3)=aaA(3)-(freq*aamur(aaslyr)*mue0*pi*cBes(0))/2
!!! endif
!!! aaA(5)=(kkphase(aaslyr)**2)*aaA(5)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
!!! aaA(4)=(kkphase(aaslyr)**2)*aaA(4)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
!!! aaA(3)=(kkphase(aaslyr)**2)*aaA(3)
!!! aaA(2)=-(aaepsr(aaslyr)/aaepsr(aaolyr))*((kkphase(aaslyr)**2)*aaA(2)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2))*kgamma/(freq*2*pi*eps0*aaepsr(aaslyr))
!!! aaA(1)=(aaepsr(aaolyr)/aaepsr(aaslyr))*((kkphase(aaslyr)**2)*aaA(1)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2))*kgamma/(freq*2*pi*eps0*aaepsr(aaslyr))
!!! aaA(6)=aaA(6)
!!elseif (aaiHEK.eq.1) then
!!!Warning: Here epsilon and mu values are interchanged to convert from TE to TM. (by geomnormer)
!! aaA(6)=Ci*freq*2*pi*ress(1)*eps0/mue0 !Hzz
!! aaA(2)=-ress(2)/(mue0*aamur(aaolyr)) !
!! aaA(1)=ress(3)/(mue0*aamur(aaolyr)) !
!! if (aaslyr.eq.aaolyr) then !direct term inclusion
!! distx=dcmplx(aarho,aarhoi)
!! distz=dcmplx(aaz,aazi)
!! dist=cdsqrt(distx**2+distz**2) !complex distance
!! if (dreal(dist).lt.0.0) dist=-dist ! the real part of the distance must be positive
!! if (dimag(aakk(aaslyr)).gt.0.0) then
!! dist=-dist*aakk(aaslyr) ! argument of the hankel function
!! else
!! dist=dist*aakk(aaslyr) ! argument of the hankel function
!! endif
!! idumy1=2
!! idumy2=20
!! idumy3=14
!! call ch2(dist,cBes(0),idumy1,idumy2,idumy3,ierr)
!! if(ierr.gt.0) cBes=(0.0d0,0.0d0)
!! if((ierr.ne.0).and.lDispWarn) then
!! write(*,*) 'WARNING: Error',ierr,' in Bessel(',dist,')'
!! lDispWarn=.false.
!! end if
!! aaA(2)=aaA(2)-(Ci*aakk(aaslyr)*aakk(aaslyr)*distx*cBes(1))/(4*dist)
!! aaA(1)=aaA(1)+(Ci*aakk(aaslyr)*aakk(aaslyr)*distz*cBes(1))/(4*dist)
!! aaA(6)=aaA(6)+(freq*aamur(aaslyr)*eps0*pi*cBes(0))/2
!! endif
!! aaA(2)=aaA(2)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
!! aaA(1)=aaA(1)*(k00**2)*aaepsr(aaslyr)*aamur(aaslyr)/(aakk(aaslyr)**2)
!!endif
!! call normer(aaA,r,aaiHEK,1)
!! rimag=rimag/aafreq_norm
!!
!!endsubroutine twodlyrbase_kgamma
subroutine normer(aaA,r,aaiHEK,ssaa)
implicit none
integer ssaa
complex*16 aaA(10,ssaa), dumm(0:mxlyr)
real*8 r(3)
Integer(4) i, aaiHEK
aaA=aaA*aafreq_norm
r=r/aafreq_norm
aah=aah/aafreq_norm
do i=1,aanoflyr-2
aadd(i)=aadd(i)/aafreq_norm
enddo
if (aaiHEK.eq.1) then
dumm=aaepsr
aaepsr=aamur
aamur=dumm
if (peccheck(1).eq.1) then
peccheck(1)=2
elseif (peccheck(1).eq.2) then
peccheck(1)=1
endif
if (peccheck(2).eq.2) then
peccheck(2)=1
elseif (peccheck(2).eq.1) then
peccheck(2)=2
endif
endif
endsubroutine normer
subroutine geomnormer(r,obs_lyr)
implicit none
real*8 r(3)
Integer(4) i,obs_lyr
aah=aah*aafreq_norm
aadd(1:aanoflyr-2)=aadd(1:aanoflyr-2)*aafreq_norm
r=r*aafreq_norm
do i=1,aanoflyr
aaepsr(i-1)=dreal(eDom(i))-Ci*dimag(eDom(i))
aamur(i-1)=dreal(uDom(i))-Ci*dimag(uDom(i))
enddo
aaslyr=source_lyr-1
aaolyr=obs_lyr-1
endsubroutine geomnormer
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! BESSEL FUNCTIONS J0 J1 and Y0 FOR ANY real*8 VARIABLE aax !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
real*8 function bsj0(aax)
real*8 y,p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,xx,aax,z,ax
real*8 r1,r2,r3,r4,r5,r6,s1,s2,s3,s4,s5,s6
data p1,p2,p3,p4,p5/1.d0,-0.1098628627d-2,0.2734510407d-4,-0.2073370639d-5,0.2093887211d-6/
data q1,q2,q3,q4,q5/-0.1562499995d-1,0.1430488765d-3,-0.6911147651d-5,0.7621095161d-6,-0.934945152d-7/
data r1,r2,r3,r4,r5,r6/57568490574.0d0,-13362590354.0d0,651619640.7d0,-11214424.18d0,77392.33017d0,-184.9052456d0/
data s1,s2,s3,s4,s5,s6/57568490411.0d0,1029532985.0d0,9494680.718d0,59272.64853d0,267.8532712d0,1.d0/
!
if(dabs(aax).lt.8.0d0) then
y=aax**2
bsj0=(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))
else