-
Notifications
You must be signed in to change notification settings - Fork 2
/
calculations.c
1523 lines (1256 loc) · 31.7 KB
/
calculations.c
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
/*** Translated to the C language by N. Kyriazis 20 Aug 2003 ***
Program NEC(input,tape5=input,output,tape11,tape12,tape13,tape14,
tape15,tape16,tape20,tape21)
Numerical Electromagnetics Code (NEC2) developed at Lawrence
Livermore lab., Livermore, CA. (contact G. Burke at 415-422-8414
for problems with the NEC code. For problems with the vax implem-
entation, contact J. Breakall at 415-422-8196 or E. Domning at 415
422-5936)
file created 4/11/80.
***********Notice**********
This computer code material was prepared as an account of work
sponsored by the United States government. Neither the United
States nor the United States Department Of Energy, nor any of
their employees, nor any of their contractors, subcontractors,
or their employees, makes any warranty, express or implied, or
assumes any legal liability or responsibility for the accuracy,
completeness or usefulness of any information, apparatus, product
or process disclosed, or represents that its use would not infringe
privately-owned rights.
******************************************************************/
#include "nec2c.h"
#include "shared.h"
/*-----------------------------------------------------------------------*/
/* cabc computes coefficients of the constant (a), sine (b), and */
/* cosine (c) terms in the current interpolation functions for the */
/* current vector cur. */
void cabc( complex double *curx)
{
int i, is, j, jx, jco1, jco2;
double ar, ai, sh;
complex double curd, cs1, cs2;
if( data.n != 0)
{
for( i = 0; i < data.n; i++ )
{
crnt.air[i]=0.;
crnt.aii[i]=0.;
crnt.bir[i]=0.;
crnt.bii[i]=0.;
crnt.cir[i]=0.;
crnt.cii[i]=0.;
}
for( i = 0; i < data.n; i++ )
{
ar= creal( curx[i]);
ai= cimag( curx[i]);
tbf( i+1, 1 );
for( jx = 0; jx < segj.jsno; jx++ )
{
j= segj.jco[jx]-1;
crnt.air[j] += segj.ax[jx]* ar;
crnt.aii[j] += segj.ax[jx]* ai;
crnt.bir[j] += segj.bx[jx]* ar;
crnt.bii[j] += segj.bx[jx]* ai;
crnt.cir[j] += segj.cx[jx]* ar;
crnt.cii[j] += segj.cx[jx]* ai;
}
} /* for( i = 0; i < n; i++ ) */
if( vsorc.nqds != 0)
{
for( is = 0; is < vsorc.nqds; is++ )
{
i= vsorc.iqds[is]-1;
jx= data.icon1[i];
data.icon1[i]=0;
tbf(i+1,0);
data.icon1[i]= jx;
sh= data.si[i]*.5;
curd= CCJ* vsorc.vqds[is]/( (log(2.* sh/ data.bi[i])-1.)*
(segj.bx[segj.jsno-1]* cos(TP* sh)+ segj.cx[segj.jsno-1]*
sin(TP* sh))* data.wlam );
ar= creal( curd);
ai= cimag( curd);
for( jx = 0; jx < segj.jsno; jx++ )
{
j= segj.jco[jx]-1;
crnt.air[j]= crnt.air[j]+ segj.ax[jx]* ar;
crnt.aii[j]= crnt.aii[j]+ segj.ax[jx]* ai;
crnt.bir[j]= crnt.bir[j]+ segj.bx[jx]* ar;
crnt.bii[j]= crnt.bii[j]+ segj.bx[jx]* ai;
crnt.cir[j]= crnt.cir[j]+ segj.cx[jx]* ar;
crnt.cii[j]= crnt.cii[j]+ segj.cx[jx]* ai;
}
} /* for( is = 0; is < vsorc.nqds; is++ ) */
} /* if( vsorc.nqds != 0) */
for( i = 0; i < data.n; i++ )
curx[i]= cmplx( crnt.air[i]+crnt.cir[i], crnt.aii[i]+crnt.cii[i] );
} /* if( n != 0) */
if( data.m == 0)
return;
/* convert surface currents from */
/* t1,t2 components to x,y,z components */
jco1= data.np2m;
jco2= jco1+ data.m;
for( i = 1; i <= data.m; i++ )
{
jco1 -= 2;
jco2 -= 3;
cs1= curx[jco1];
cs2= curx[jco1+1];
curx[jco2] = cs1* data.t1x[data.m-i]+ cs2* data.t2x[data.m-i];
curx[jco2+1]= cs1* data.t1y[data.m-i]+ cs2* data.t2y[data.m-i];
curx[jco2+2]= cs1* data.t1z[data.m-i]+ cs2* data.t2z[data.m-i];
}
return;
}
/*-----------------------------------------------------------------------*/
/* couple computes the maximum coupling between pairs of segments. */
void couple( complex double *cur, double wlam )
{
int j, j1, j2, l1, i, k, itt1, itt2, its1, its2, isg1, isg2, npm1;
double dbc, c, gmax;
complex double y11, y12, y22, yl, yin, zl, zin, rho;
size_t mreq;
if( (vsorc.nsant != 1) || (vsorc.nvqd != 0) )
return;
j= isegno( yparm.nctag[yparm.icoup], yparm.ncseg[yparm.icoup]);
if( j != vsorc.isant[0] )
return;
zin= vsorc.vsant[0];
yparm.icoup++;
mreq = (size_t)yparm.icoup;
mreq *= sizeof( complex double);
mem_realloc( (void *)&yparm.y11a, mreq );
yparm.y11a[yparm.icoup-1]= cur[j-1]*wlam/zin;
l1=(yparm.icoup-1)*(yparm.ncoup-1);
for( i = 0; i < yparm.ncoup; i++ )
{
if( (i+1) == yparm.icoup)
continue;
l1++;
mreq = (size_t)l1;
mreq *= sizeof( complex double);
mem_realloc( (void *)&yparm.y12a, mreq );
k= isegno( yparm.nctag[i], yparm.ncseg[i]);
yparm.y12a[l1-1]= cur[k-1]* wlam/ zin;
}
if( yparm.icoup < yparm.ncoup)
return;
fprintf( output_fp, "\n\n\n"
" -----------"
" ISOLATION DATA -----------\n\n"
" ------- COUPLING BETWEEN ------ MAXIMUM "
" ---------- FOR MAXIMUM COUPLING ----------\n"
" SEG SEG COUPLING LOAD"
" IMPEDANCE (2ND SEG) INPUT IMPEDANCE \n"
" TAG SEG No: TAG SEG No: (DB) "
" REAL IMAGINARY REAL IMAGINARY" );
npm1= yparm.ncoup-1;
for( i = 0; i < npm1; i++ )
{
itt1= yparm.nctag[i];
its1= yparm.ncseg[i];
isg1= isegno( itt1, its1);
l1= i+1;
for( j = l1; j < yparm.ncoup; j++ )
{
itt2= yparm.nctag[j];
its2= yparm.ncseg[j];
isg2= isegno( itt2, its2);
j1= j+ i* npm1-1;
j2= i+ j* npm1;
y11= yparm.y11a[i];
y22= yparm.y11a[j];
y12=.5*( yparm.y12a[j1]+ yparm.y12a[j2]);
yin= y12* y12;
dbc= cabs( yin);
c= dbc/(2.* creal( y11)* creal( y22)- creal( yin));
if( (c >= 0.0) && (c <= 1.0) )
{
if( c >= .01 )
gmax=(1.- sqrt(1.- c*c))/c;
else
gmax=.5*( c+.25* c* c* c);
rho= gmax* conj( yin)/ dbc;
yl=((1.- rho)/(1.+ rho)+1.)* creal( y22)- y22;
zl=1./ yl;
yin= y11- yin/( y22+ yl);
zin=1./ yin;
dbc= db10( gmax);
fprintf( output_fp, "\n"
" %4d %4d %5d %4d %4d %5d %9.3f"
" %12.5E %12.5E %12.5E %12.5E",
itt1, its1, isg1, itt2, its2, isg2, dbc,
creal(zl), cimag(zl), creal(zin), cimag(zin) );
continue;
} /* if( (c >= 0.0) && (c <= 1.0) ) */
fprintf( output_fp, "\n"
" %4d %4d %5d %4d %4d %5d **ERROR** "
"COUPLING IS NOT BETWEEN 0 AND 1. (= %12.5E)",
itt1, its1, isg1, itt2, its2, isg2, c );
} /* for( j = l1; j < yparm.ncoup; j++ ) */
} /* for( i = 0; i < npm1; i++ ) */
return;
}
/*-----------------------------------------------------------------------*/
/* load calculates the impedance of specified */
/* segments for various types of loading */
void load( int *ldtyp, int *ldtag, int *ldtagf, int *ldtagt,
double *zlr, double *zli, double *zlc )
{
int i, iwarn, istep, istepx, l1, l2, ldtags, jump, ichk;
complex double zt=CPLX_00, tpcj;
size_t mreq;
tpcj = (0.0+I*1.883698955e+9);
fprintf( output_fp, "\n"
" LOCATION RESISTANCE INDUCTANCE CAPACITANCE "
" IMPEDANCE (OHMS) CONDUCTIVITY CIRCUIT\n"
" ITAG FROM THRU OHMS HENRYS FARADS "
" REAL IMAGINARY MHOS/METER TYPE" );
/* initialize d array, used for temporary */
/* storage of loading information. */
mreq = (size_t)data.npm;
mreq *= sizeof(complex double);
mem_realloc( (void *)&zload.zarray, mreq );
for( i = 0; i < data.n; i++ )
zload.zarray[i]=CPLX_00;
iwarn=FALSE;
istep=0;
/* cycle over loading cards */
while( TRUE )
{
istepx = istep;
istep++;
if( istep > zload.nload)
{
if( iwarn == TRUE )
fprintf( output_fp,
"\n NOTE, SOME OF THE ABOVE SEGMENTS "
"HAVE BEEN LOADED TWICE - IMPEDANCES ADDED" );
smat.nop = data.n/data.np;
if( smat.nop == 1)
return;
for( i = 0; i < data.np; i++ )
{
zt= zload.zarray[i];
l1= i;
for( l2 = 1; l2 < smat.nop; l2++ )
{
l1 += data.np;
zload.zarray[l1]= zt;
}
}
return;
} /* if( istep > zload.nload) */
if( ldtyp[istepx] > 5 )
{
fprintf( output_fp,
"\n IMPROPER LOAD TYPE CHOSEN,"
" REQUESTED TYPE IS %d", ldtyp[istepx] );
stop(-1);
}
/* search segments for proper itags */
ldtags= ldtag[istepx];
jump= ldtyp[istepx]+1;
ichk=0;
l1= 1;
l2= data.n;
if( ldtags == 0)
{
if( (ldtagf[istepx] != 0) || (ldtagt[istepx] != 0) )
{
l1= ldtagf[istepx];
l2= ldtagt[istepx];
} /* if( (ldtagf[istepx] != 0) || (ldtagt[istepx] != 0) ) */
} /* if( ldtags == 0) */
for( i = l1-1; i < l2; i++ )
{
if( ldtags != 0)
{
if( ldtags != data.itag[i])
continue;
if( ldtagf[istepx] != 0)
{
ichk++;
if( (ichk < ldtagf[istepx]) || (ichk > ldtagt[istepx]) )
continue;
}
else
ichk=1;
} /* if( ldtags != 0) */
else
ichk=1;
/* calculation of lamda*imped. per unit length, */
/* jump to appropriate section for loading type */
switch( jump )
{
case 1:
zt= zlr[istepx]/ data.si[i]+ tpcj* zli[istepx]/( data.si[i]* data.wlam);
if( fabs( zlc[istepx]) > 1.0e-20)
zt += data.wlam/( tpcj* data.si[i]* zlc[istepx]);
break;
case 2:
zt= tpcj* data.si[i]* zlc[istepx]/ data.wlam;
if( fabs( zli[istepx]) > 1.0e-20)
zt += data.si[i]* data.wlam/( tpcj* zli[istepx]);
if( fabs( zlr[istepx]) > 1.0e-20)
zt += data.si[i]/ zlr[istepx];
zt=1./ zt;
break;
case 3:
zt= zlr[istepx]* data.wlam+ tpcj* zli[istepx];
if( fabs( zlc[istepx]) > 1.0e-20)
zt += 1./( tpcj* data.si[i]* data.si[i]* zlc[istepx]);
break;
case 4:
zt= tpcj* data.si[i]* data.si[i]* zlc[istepx];
if( fabs( zli[istepx]) > 1.0e-20)
zt += 1./( tpcj* zli[istepx]);
if( fabs( zlr[istepx]) > 1.0e-20)
zt += 1./( zlr[istepx]* data.wlam);
zt=1./ zt;
break;
case 5:
zt= cmplx( zlr[istepx], zli[istepx])/ data.si[i];
break;
case 6:
zint( zlr[istepx]* data.wlam, data.bi[i], &zt );
} /* switch( jump ) */
if(( fabs( creal( zload.zarray[i]))+ fabs( cimag( zload.zarray[i]))) > 1.0e-20)
iwarn=TRUE;
zload.zarray[i] += zt;
} /* for( i = l1-1; i < l2; i++ ) */
if( ichk == 0 )
{
fprintf( output_fp,
"\n LOADING DATA CARD ERROR,"
" NO SEGMENT HAS AN ITAG = %d", ldtags );
stop(-1);
}
/* printing the segment loading data, jump to proper print */
switch( jump )
{
case 1:
prnt( ldtags, ldtagf[istepx], ldtagt[istepx], zlr[istepx],
zli[istepx], zlc[istepx],0.,0.,0.," SERIES ", 2);
break;
case 2:
prnt( ldtags, ldtagf[istepx], ldtagt[istepx], zlr[istepx],
zli[istepx], zlc[istepx],0.,0.,0.,"PARALLEL",2);
break;
case 3:
prnt( ldtags, ldtagf[istepx], ldtagt[istepx], zlr[istepx],
zli[istepx], zlc[istepx],0.,0.,0., "SERIES (PER METER)", 5);
break;
case 4:
prnt( ldtags, ldtagf[istepx], ldtagt[istepx], zlr[istepx],
zli[istepx], zlc[istepx],0.,0.,0.,"PARALLEL (PER METER)",5);
break;
case 5:
prnt( ldtags, ldtagf[istepx], ldtagt[istepx],0.,0.,0.,
zlr[istepx], zli[istepx],0.,"FIXED IMPEDANCE ",4);
break;
case 6:
prnt( ldtags, ldtagf[istepx], ldtagt[istepx],
0.,0.,0.,0.,0., zlr[istepx]," WIRE ",2);
} /* switch( jump ) */
} /* while( TRUE ) */
}
/*-----------------------------------------------------------------------*/
/* gf computes the integrand exp(jkr)/(kr) for numerical integration. */
void gf( double zk, double *co, double *si )
{
double zdk, rk, rks;
zdk= zk- tmi.zpk;
rk= sqrt( tmi.rkb2+ zdk* zdk);
*si= sin( rk)/ rk;
if( tmi.ij != 0 )
{
*co= cos( rk)/ rk;
return;
}
if( rk >= .2)
{
*co=( cos( rk)-1.)/ rk;
return;
}
rks= rk* rk;
*co=((-1.38888889e-3* rks+4.16666667e-2)* rks-.5)* rk;
return;
}
/*-----------------------------------------------------------------------*/
/* function db10 returns db for magnitude (field) */
double db10( double x )
{
if( x < 1.e-20 )
return( -999.99 );
return( 10. * log10(x) );
}
/*-----------------------------------------------------------------------*/
/* function db20 returns db for mag**2 (power) i */
double db20( double x )
{
if( x < 1.e-20 )
return( -999.99 );
return( 20. * log10(x) );
}
/*-----------------------------------------------------------------------*/
/* intrp uses bivariate cubic interpolation to obtain */
/* the values of 4 functions at the point (x,y). */
void intrp( double x, double y, complex double *f1,
complex double *f2, complex double *f3, complex double *f4 )
{
static int ix, iy, ixs=-10, iys=-10, igrs=-10, ixeg=0, iyeg=0;
static int nxm2, nym2, nxms, nyms, nd, ndp;
int nda[3]={11,17,9}, ndpa[3]={110,85,72};
int jump;
static double dx = 1., dy = 1., xs = 0., ys = 0., xz, yz;
double xx, yy;
static complex double a[4][4], b[4][4], c[4][4], d[4][4];
complex double p1=CPLX_00, p2=CPLX_00, p3=CPLX_00, p4=CPLX_00;
complex double fx1, fx2, fx3, fx4;
jump = FALSE;
if( (x < xs) || (y < ys) )
jump = TRUE;
else
{
ix= (int)(( x- xs)/ dx)+1;
iy= (int)(( y- ys)/ dy)+1;
}
/* if point lies in same 4 by 4 point region */
/* as previous point, old values are reused. */
if( (ix < ixeg) ||
(iy < iyeg) ||
(abs(ix- ixs) >= 2) ||
(abs(iy- iys) >= 2) ||
jump )
{
int igr, iadd, iadz, i, k;
/* determine correct grid and grid region */
if( x <= ggrid.xsa[1])
igr=0;
else
{
if( y > ggrid.ysa[2])
igr=2;
else
igr=1;
}
if( igr != igrs)
{
igrs= igr;
dx= ggrid.dxa[igrs];
dy= ggrid.dya[igrs];
xs= ggrid.xsa[igrs];
ys= ggrid.ysa[igrs];
nxm2= ggrid.nxa[igrs]-2;
nym2= ggrid.nya[igrs]-2;
nxms=(( nxm2+1)/3)*3+1;
nyms=(( nym2+1)/3)*3+1;
nd= nda[igrs];
ndp= ndpa[igrs];
ix= (int)(( x- xs)/ dx)+1;
iy= (int)(( y- ys)/ dy)+1;
} /* if( igr != igrs) */
ixs=(( ix-1)/3)*3+2;
if( ixs < 2)
ixs=2;
ixeg=-10000;
if( ixs > nxm2)
{
ixs= nxm2;
ixeg= nxms;
}
iys=(( iy-1)/3)*3+2;
if( iys < 2)
iys=2;
iyeg=-10000;
if( iys > nym2)
{
iys= nym2;
iyeg= nyms;
}
/* compute coefficients of 4 cubic polynomials in x for */
/* the 4 grid values of y for each of the 4 functions */
iadz= ixs+( iys-3)* nd- ndp;
for( k = 0; k < 4; k++ )
{
iadz += ndp;
iadd = iadz;
for( i = 0; i < 4; i++ )
{
iadd += nd;
switch( igrs )
{
case 0:
p1= ggrid.ar1[iadd-2];
p2= ggrid.ar1[iadd-1];
p3= ggrid.ar1[iadd];
p4= ggrid.ar1[iadd+1];
break;
case 1:
p1= ggrid.ar2[iadd-2];
p2= ggrid.ar2[iadd-1];
p3= ggrid.ar2[iadd];
p4= ggrid.ar2[iadd+1];
break;
case 2:
p1= ggrid.ar3[iadd-2];
p2= ggrid.ar3[iadd-1];
p3= ggrid.ar3[iadd];
p4= ggrid.ar3[iadd+1];
} /* switch( igrs ) */
a[i][k]=( p4- p1+3.*( p2- p3))*.1666666667;
b[i][k]=( p1-2.* p2+ p3)*.5;
c[i][k]= p3-(2.* p1+3.* p2+ p4)*.1666666667;
d[i][k]= p2;
} /* for( i = 0; i < 4; i++ ) */
} /* for( k = 0; k < 4; k++ ) */
xz=( ixs-1)* dx+ xs;
yz=( iys-1)* dy+ ys;
} /* if( (abs(ix- ixs) >= 2) || */
/* evaluate polymomials in x and use cubic */
/* interpolation in y for each of the 4 functions. */
xx=( x- xz)/ dx;
yy=( y- yz)/ dy;
fx1=(( a[0][0]* xx+ b[0][0])* xx+ c[0][0])* xx+ d[0][0];
fx2=(( a[1][0]* xx+ b[1][0])* xx+ c[1][0])* xx+ d[1][0];
fx3=(( a[2][0]* xx+ b[2][0])* xx+ c[2][0])* xx+ d[2][0];
fx4=(( a[3][0]* xx+ b[3][0])* xx+ c[3][0])* xx+ d[3][0];
p1= fx4- fx1+3.*( fx2- fx3);
p2=3.*( fx1-2.* fx2+ fx3);
p3=6.* fx3-2.* fx1-3.* fx2- fx4;
*f1=(( p1* yy+ p2)* yy+ p3)* yy*.1666666667+ fx2;
fx1=(( a[0][1]* xx+ b[0][1])* xx+ c[0][1])* xx+ d[0][1];
fx2=(( a[1][1]* xx+ b[1][1])* xx+ c[1][1])* xx+ d[1][1];
fx3=(( a[2][1]* xx+ b[2][1])* xx+ c[2][1])* xx+ d[2][1];
fx4=(( a[3][1]* xx+ b[3][1])* xx+ c[3][1])* xx+ d[3][1];
p1= fx4- fx1+3.*( fx2- fx3);
p2=3.*( fx1-2.* fx2+ fx3);
p3=6.* fx3-2.* fx1-3.* fx2- fx4;
*f2=(( p1* yy+ p2)* yy+ p3)* yy*.1666666667+ fx2;
fx1=(( a[0][2]* xx+ b[0][2])* xx+ c[0][2])* xx+ d[0][2];
fx2=(( a[1][2]* xx+ b[1][2])* xx+ c[1][2])* xx+ d[1][2];
fx3=(( a[2][2]* xx+ b[2][2])* xx+ c[2][2])* xx+ d[2][2];
fx4=(( a[3][2]* xx+ b[3][2])* xx+ c[3][2])* xx+ d[3][2];
p1= fx4- fx1+3.*( fx2- fx3);
p2=3.*( fx1-2.* fx2+ fx3);
p3=6.* fx3-2.* fx1-3.* fx2- fx4;
*f3=(( p1* yy+ p2)* yy+ p3)* yy*.1666666667+ fx2;
fx1=(( a[0][3]* xx+ b[0][3])* xx+ c[0][3])* xx+ d[0][3];
fx2=(( a[1][3]* xx+ b[1][3])* xx+ c[1][3])* xx+ d[1][3];
fx3=(( a[2][3]* xx+ b[2][3])* xx+ c[2][3])* xx+ d[2][3];
fx4=(( a[3][3]* xx+ b[3][3])* xx+ c[3][3])* xx+ d[3][3];
p1= fx4- fx1+3.*( fx2- fx3);
p2=3.*( fx1-2.* fx2+ fx3);
p3=6.* fx3-2.* fx1-3.* fx2- fx4;
*f4=(( p1* yy+ p2)* yy+ p3)* yy*.16666666670+ fx2;
return;
}
/*-----------------------------------------------------------------------*/
/* intx performs numerical integration of exp(jkr)/r by the method of */
/* variable interval width romberg integration. the integrand value */
/* is supplied by subroutine gf. */
void intx( double el1, double el2, double b,
int ij, double *sgr, double *sgi)
{
int ns, nt;
int nx = 1, nma = 65536, nts = 4;
int flag = TRUE;
double z, s, ze, fnm, ep, zend, fns, dz=0., zp, dzot=0., t00r, g1r, g5r=0.0, t00i;
double g1i, g5i=0.0, t01r, g3r=0.0, t01i, g3i=0.0, t10r, t10i, te1i, te1r, t02r;
double g2r, g4r, t02i, g2i, g4i, t11r, t11i, t20r, t20i, te2i, te2r;
double rx = 1.0e-4;
z= el1;
ze= el2;
if( ij == 0)
ze=0.;
s= ze- z;
fnm= nma;
ep= s/(10.* fnm);
zend= ze- ep;
*sgr=0.;
*sgi=0.;
ns= nx;
nt=0;
gf( z, &g1r, &g1i);
while( TRUE )
{
if( flag )
{
fns= ns;
dz= s/ fns;
zp= z+ dz;
if( zp > ze)
{
dz= ze- z;
if( fabs(dz) <= ep)
{
/* add contribution of near singularity for diagonal term */
if(ij == 0)
{
*sgr=2.*( *sgr+ log(( sqrt( b* b+ s* s)+ s)/ b));
*sgi=2.* *sgi;
}
return;
}
} /* if( zp > ze) */
dzot= dz*.5;
zp= z+ dzot;
gf( zp, &g3r, &g3i);
zp= z+ dz;
gf( zp, &g5r, &g5i);
} /* if( flag ) */
t00r=( g1r+ g5r)* dzot;
t00i=( g1i+ g5i)* dzot;
t01r=( t00r+ dz* g3r)*0.5;
t01i=( t00i+ dz* g3i)*0.5;
t10r=(4.0* t01r- t00r)/3.0;
t10i=(4.0* t01i- t00i)/3.0;
/* test convergence of 3 point romberg result. */
test( t01r, t10r, &te1r, t01i, t10i, &te1i, 0.);
if( (te1i <= rx) && (te1r <= rx) )
{
*sgr= *sgr+ t10r;
*sgi= *sgi+ t10i;
nt += 2;
z += dz;
if( z >= zend)
{
/* add contribution of near singularity for diagonal term */
if(ij == 0)
{
*sgr=2.*( *sgr+ log(( sqrt( b* b+ s* s)+ s)/ b));
*sgi=2.* *sgi;
}
return;
}
g1r= g5r;
g1i= g5i;
if( nt >= nts)
if( ns > nx)
{
/* Double step size */
ns= ns/2;
nt=1;
}
flag = TRUE;
continue;
} /* if( (te1i <= rx) && (te1r <= rx) ) */
zp= z+ dz*0.25;
gf( zp, &g2r, &g2i);
zp= z+ dz*0.75;
gf( zp, &g4r, &g4i);
t02r=( t01r+ dzot*( g2r+ g4r))*0.5;
t02i=( t01i+ dzot*( g2i+ g4i))*0.5;
t11r=(4.0* t02r- t01r)/3.0;
t11i=(4.0* t02i- t01i)/3.0;
t20r=(16.0* t11r- t10r)/15.0;
t20i=(16.0* t11i- t10i)/15.0;
/* test convergence of 5 point romberg result. */
test( t11r, t20r, &te2r, t11i, t20i, &te2i, 0.);
if( (te2i > rx) || (te2r > rx) )
{
nt=0;
if( ns >= nma)
fprintf( output_fp, "\n STEP SIZE LIMITED AT Z= %10.5f", z );
else
{
/* halve step size */
ns= ns*2;
fns= ns;
dz= s/ fns;
dzot= dz*0.5;
g5r= g3r;
g5i= g3i;
g3r= g2r;
g3i= g2i;
flag = FALSE;
continue;
}
} /* if( (te2i > rx) || (te2r > rx) ) */
*sgr= *sgr+ t20r;
*sgi= *sgi+ t20i;
nt++;
z += dz;
if( z >= zend)
{
/* add contribution of near singularity for diagonal term */
if(ij == 0)
{
*sgr=2.*( *sgr+ log(( sqrt( b* b+ s* s)+ s)/ b));
*sgi=2.* *sgi;
}
return;
}
g1r= g5r;
g1i= g5i;
if( nt >= nts)
if( ns > nx)
{
/* Double step size */
ns= ns/2;
nt=1;
}
flag = TRUE;
} /* while( TRUE ) */
}
/*-----------------------------------------------------------------------*/
/* returns smallest of two arguments */
int min( int a, int b )
{
if( a < b )
return(a);
else
return(b);
}
/*-----------------------------------------------------------------------*/
/* test for convergence in numerical integration */
void test( double f1r, double f2r, double *tr,
double f1i, double f2i, double *ti, double dmin )
{
double den;
den= fabs( f2r);
*tr= fabs( f2i);
if( den < *tr)
den= *tr;
if( den < dmin)
den= dmin;
if( den < 1.0e-37)
{
*tr=0.;
*ti=0.;
return;
}
*tr= fabs(( f1r- f2r)/ den);
*ti= fabs(( f1i- f2i)/ den);
return;
}
/*-----------------------------------------------------------------------*/
/* compute component of basis function i on segment is. */
void sbf( int i, int is, double *aa, double *bb, double *cc )
{
int ix, jsno, june, jcox, jcoxx, jend, iend, njun1=0, njun2;
double d, sig, pp, sdh, cdh, sd, omc, aj, pm=0, cd, ap, qp, qm, xxi;
*aa=0.;
*bb=0.;
*cc=0.;
june=0;
jsno=0;
pp=0.;
ix=i-1;
jcox= data.icon1[ix];
if( jcox > PCHCON) jcox= i;
jend=-1;
iend=-1;
sig=-1.;
do
{
if( jcox != 0 )
{
if( jcox < 0 )
jcox= -jcox;
else
{
sig= -sig;
jend= -jend;
}
jcoxx = jcox-1;
jsno++;
d= PI* data.si[jcoxx];
sdh= sin( d);
cdh= cos( d);
sd=2.* sdh* cdh;
if( d <= 0.015)
{
omc=4.* d* d;
omc=((1.3888889e-3* omc -4.1666666667e-2)* omc +.5)* omc;
}
else
omc=1.- cdh* cdh+ sdh* sdh;
aj=1./( log(1./( PI* data.bi[jcoxx]))-.577215664);
pp -= omc/ sd* aj;
if( jcox == is)
{
*aa= aj/ sd* sig;
*bb= aj/(2.* cdh);
*cc= -aj/(2.* sdh)* sig;
june= iend;
}
if( jcox != i )
{
if( jend != 1)
jcox= data.icon1[jcoxx];
else
jcox= data.icon2[jcoxx];
if( abs(jcox) != i )
{
if( jcox == 0 )
{
fprintf( output_fp,
"\n SBF - SEGMENT CONNECTION ERROR FOR SEGMENT %d", i);
stop(-1);
}
else
continue;
}
} /* if( jcox != i ) */
else
if( jcox == is)
*bb= -*bb;
if( iend == 1)
break;
} /* if( jcox != 0 ) */
pm= -pp;
pp=0.;
njun1= jsno;
jcox= data.icon2[ix];
if( jcox > PCHCON) jcox= i;
jend=1;
iend=1;
sig=-1.;
} /* do */
while( jcox != 0 );
njun2= jsno- njun1;
d= PI* data.si[ix];
sdh= sin( d);
cdh= cos( d);
sd=2.* sdh* cdh;
cd= cdh* cdh- sdh* sdh;
if( d <= 0.015)
{
omc=4.* d* d;
omc=((1.3888889e-3* omc -4.1666666667e-2)* omc +.5)* omc;
}
else
omc=1.- cd;
ap=1./( log(1./( PI* data.bi[ix])) -.577215664);
aj= ap;
if( njun1 == 0)
{