Subversion Repositories Nec2c

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef NEC2C_H
  2. #define NEC2C_H 1
  3.  
  4. #include <complex.h>
  5. #include <errno.h>
  6. #include <fcntl.h>
  7. #include <math.h>
  8. #include <signal.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <sys/time.h>
  13. #include <sys/types.h>
  14. #include <time.h>
  15. #include <unistd.h>
  16.  
  17. #ifndef TRUE
  18. #define TRUE 1
  19. #endif
  20.  
  21. #ifndef FALSE
  22. #define FALSE 0
  23. #endif
  24.  
  25. /* commonly used complex constants */
  26. #define CPLX_00 (0.0 + 0.0fj)
  27. #define CPLX_01 (0.0 + 1.0fj)
  28. #define CPLX_10 (1.0 + 0.0fj)
  29. #define CPLX_11 (1.0 + 1.0fj)
  30.  
  31. /* common constants */
  32. #define PI 3.141592654
  33. #define POT 1.570796327
  34. #define TP 6.283185308
  35. #define PTP .6283185308
  36. #define TPJ (0.0 + 6.283185308fj)
  37. #define PI8 25.13274123
  38. #define PI10 31.41592654
  39. #define TA 1.745329252E-02
  40. #define TD 57.29577951
  41. #define ETA 376.73
  42. #define CVEL 299.8
  43. #define RETA 2.654420938E-3
  44. #define TOSP 1.128379167
  45. #define ACCS 1.E-12
  46. #define SP 1.772453851
  47. #define FPI 12.56637062
  48. #define CCJ (0.0 - 0.01666666667fj)
  49. #define CONST1 (0.0 + 4.771341189fj)
  50. #define CONST2 4.771341188
  51. #define CONST3 (0.0 - 29.97922085fj)
  52. #define CONST4 (0.0 + 188.365fj)
  53. #define GAMMA .5772156649
  54. #define C1 -.02457850915
  55. #define C2 .3674669052
  56. #define C3 .7978845608
  57. #define P10 .0703125
  58. #define P20 .1121520996
  59. #define Q10 .125
  60. #define Q20 .0732421875
  61. #define P11 .1171875
  62. #define P21 .1441955566
  63. #define Q11 .375
  64. #define Q21 .1025390625
  65. #define POF .7853981635
  66. #define MAXH 20
  67. #define CRIT 1.0E-4
  68. #define NM 131072
  69. #define NTS 4
  70. #define SMIN 1.e-3
  71.  
  72. /* Replaces the "10000" limit used to */
  73. /* identify segment/patch connections */
  74. #define PCHCON 100000
  75.  
  76. /* carriage return and line feed */
  77. #define CR 0x0d
  78. #define LF 0x0a
  79.  
  80. /* max length of a line read from input file */
  81. #define LINE_LEN 132
  82. /* version of fortran source for the -v option */
  83. #define version "nec2c 0.9"
  84.  
  85. /*** Structs encapsulating global ("common") variables ***/
  86. /* common  /crnt/ */
  87. typedef struct
  88. {
  89.         double *air, /* Ai/lambda, real part */
  90.             *aii,    /* Ai/lambda, imaginary part */
  91.             *bir,    /* Bi/lambda, real part */
  92.             *bii,    /* Bi/lambda, imaginary part */
  93.             *cir,    /* Ci/lambda, real part */
  94.             *cii;    /* Ci/lambda, imaginary part */
  95.  
  96.         complex double *cur; /* Amplitude of basis function */
  97.  
  98. } crnt_t;
  99.  
  100. /* common  /data/ (geometry data) */
  101. typedef struct
  102. {
  103.         int n,      /* Number of wire segments */
  104.             np,     /* Number of wire segments in symmetry cell */
  105.             m,      /* Number of surface patches */
  106.             mp,     /* Number of surface patches in symmetry cell */
  107.             npm,    /* = n+m  */
  108.             np2m,   /* = n+2m */
  109.             np3m,   /* = n+3m */
  110.             ipsym,  /* Symmetry flag */
  111.             *icon1, /* Segments end 1 connection */
  112.             *icon2, /* Segments end 2 connection */
  113.             *itag;  /* Segments tag number */
  114.  
  115.         /* Wire segment data */
  116.         double *x1, *y1, *z1, /* End 1 coordinates of wire segments */
  117.             *x2, *y2, *z2,    /* End 2 coordinates of wire segments */
  118.             *x, *y, *z,       /* Coordinates of segment centers */
  119.             *si, *bi,         /* Length and radius of segments  */
  120.             *cab,             /* cos(a)*cos(b) */
  121.             *sab,             /* cos(a)*sin(b) */
  122.             *salp,            /* Z component - sin(a) */
  123.  
  124.             /* Surface patch data */
  125.             *px, *py, *pz,    /* Coordinates of patch center */
  126.             *t1x, *t1y, *t1z, /* Coordinates of t1 vector */
  127.             *t2x, *t2y, *t2z, /* Coordinates of t2 vector */
  128.             *pbi,             /* Patch surface area */
  129.             *psalp,           /* Z component - sin(a) */
  130.  
  131.             /* Wavelength in meters */
  132.             wlam;
  133.  
  134. } data_t;
  135.  
  136. /* common  /dataj/ */
  137. typedef struct
  138. {
  139.         int iexk, ind1, indd1, ind2, indd2, ipgnd;
  140.  
  141.         double s, b, xj, yj, zj, cabj, sabj, salpj, rkh, t1xj, t1yj, t1zj, t2xj, t2yj, t2zj;
  142.  
  143.         complex double exk, eyk, ezk, exs, eys, ezs, exc, eyc, ezc;
  144.  
  145. } dataj_t;
  146.  
  147. /* common  /fpat/ */
  148. typedef struct
  149. {
  150.         int near, nfeh, nrx, nry, nrz, nth, nph, ipd, iavp, inor, iax, ixtyp;
  151.  
  152.         double thets, phis, dth, dph, rfld, gnor, clt, cht, epsr2, sig2, xpr6, pinr, pnlr,
  153.             ploss, xnr, ynr, znr, dxnr, dynr, dznr;
  154.  
  155. } fpat_t;
  156.  
  157. /*common  /ggrid/ */
  158. typedef struct
  159. {
  160.         int nxa[3], nya[3];
  161.  
  162.         double dxa[3], dya[3], xsa[3], ysa[3];
  163.  
  164.         complex double epscf, *ar1, *ar2, *ar3;
  165.  
  166. } ggrid_t;
  167.  
  168. /* common  /gnd/ */
  169. typedef struct
  170. {
  171.         int ksymp, /* Ground flag */
  172.             ifar,  /* Int flag in RP card, for far field calculations */
  173.             iperf, /* Type of ground flag */
  174.             nradl; /* Number of radials in ground screen */
  175.  
  176.         double t2, /* Const for radial wire ground impedance */
  177.             cl,    /* Distance in wavelengths of cliff edge from origin */
  178.             ch,    /* Cliff height in wavelengths */
  179.             scrwl, /* Wire length in radial ground screen normalized to w/length */
  180.             scrwr; /* Radius of wires in screen in wavelengths */
  181.  
  182.         complex double zrati, /* Ground medium [Er-js/wE0]^-1/2 */
  183.             zrati2,           /* As above for 2nd ground medium */
  184.             t1,               /* Const for radial wire ground impedance */
  185.             frati;            /* (k1^2-k2^2)/(k1^2+k2^2), k1=w(E0Mu0)^1/2, k1=k2/ZRATI */
  186.  
  187. } gnd_t;
  188.  
  189. /* common  /gwav/ */
  190. typedef struct
  191. {
  192.         double r1, /* Distance from current element to point where field is evaluated  */
  193.             r2,    /* Distance from image of element to point where field is evaluated */
  194.             zmh,   /* Z-Z', Z is height of field evaluation point */
  195.             zph;   /* Z+Z', Z' is height of current element */
  196.  
  197.         complex double u, /* (Er-jS/WE0)^-1/2 */
  198.             u2,           /* u^2 */
  199.             xx1,          /* G1*exp(jkR1.r[i])  */
  200.             xx2;          /* G2*exp(jkR2.r'[i]) */
  201.  
  202. } gwav_t;
  203.  
  204. /* common  /incom/ */
  205. typedef struct
  206. {
  207.         int isnor;
  208.  
  209.         double xo, yo, zo, sn, xsn, ysn;
  210.  
  211. } incom_t;
  212.  
  213. /* common  /matpar/ (matrix parameters) */
  214. typedef struct
  215. {
  216.         int icase, /* Storage mode of primary matrix */
  217.             npblk, /* Num of blocks in first (NBLOKS-1) blocks */
  218.             nlast, /* Num of blocks in last block */
  219.             imat;  /* Storage reserved in CM for primary NGF matrix A */
  220.  
  221. } matpar_t;
  222.  
  223. /* common  /netcx/ */
  224. typedef struct
  225. {
  226.         int masym,                  /* Matrix symmetry flags */
  227.             neq, npeq, neq2, nonet, /* Number of two-port networks */
  228.             ntsol,                  /* "Network equations are solved" flag */
  229.             nprint,                 /* Print control flag */
  230.             *iseg1,                 /* Num of seg to which port 1 of network is connected */
  231.             *iseg2,                 /* Num of seg to which port 2 of network is connected */
  232.             *ntyp;                  /* Type of networks */
  233.  
  234.         double *x11r, /* Real and imaginary parts of network impedances */
  235.             *x11i, *x12r, *x12i, *x22r, *x22i, pin, /* Total input power from sources */
  236.             pnls;                                   /* Power lost in networks */
  237.  
  238.         complex double zped;
  239.  
  240. } netcx_t;
  241.  
  242. /* common  /plot/ */
  243. typedef struct
  244. {
  245.         int
  246.             /* Plot control flags */
  247.             iplp1,
  248.             iplp2, iplp3, iplp4;
  249.  
  250. } plot_t;
  251.  
  252. /* common  /save/ */
  253. typedef struct
  254. {
  255.         int *ip; /* Vector of indices of pivot elements used to factor matrix */
  256.  
  257.         double epsr, /* Relative dielectric constant of ground */
  258.             sig,     /* Conductivity of ground */
  259.             scrwlt,  /* Length of radials in ground screen approximation */
  260.             scrwrt,  /* Radius of wires in ground screen approximation */
  261.             fmhz;    /* Frequency in MHz */
  262.  
  263. } save_t;
  264.  
  265. /* common  /segj/ */
  266. typedef struct
  267. {
  268.         int *jco,   /* Stores connection data */
  269.             jsno,   /* Total number of entries in ax, bx, cx */
  270.             maxcon; /* Max. no. connections */
  271.  
  272.         double *ax, *bx, *cx; /* Store constants A, B, C used in current expansion */
  273.  
  274. } segj_t;
  275.  
  276. /* common  /smat/ */
  277. typedef struct
  278. {
  279.         int nop; /* My addition */
  280.  
  281.         complex double *ssx;
  282.  
  283. } smat_t;
  284.  
  285. /* common  /tmi/ */
  286. typedef struct
  287. {
  288.         int ij;
  289.  
  290.         double zpk, rkb2;
  291.  
  292. } tmi_t;
  293.  
  294. /*common  /tmh/ */
  295. typedef struct
  296. {
  297.         double zpka, rhks;
  298.  
  299. } tmh_t;
  300.  
  301. /* common  /vsorc/ */
  302. typedef struct
  303. {
  304.         int *isant, /* Num of segs on which an aplied field source is located */
  305.             *ivqd,  /* Num of segs on which a current-slope discontinuity source is located */
  306.             *iqds,  /* Same as above (?) */
  307.             nsant,  /* Number of applied field voltage sources */
  308.             nvqd,   /* Number of applied current-slope discontinuity sources */
  309.             nqds;   /* Same as above (?) */
  310.  
  311.         complex double *vqd, /* Voltage of applied-current slope discontinuity sources */
  312.             *vqds,           /* Same as above (?) */
  313.             *vsant;          /* Voltages of applied field voltage sources */
  314.  
  315. } vsorc_t;
  316.  
  317. /* common  /yparm/ */
  318. typedef struct
  319. {
  320.         int ncoup,  /* Num of segs between which coupling will be computed */
  321.             icoup,  /* Num of segs in the coupling array that have been excited */
  322.             *nctag, /* Tag number of segments */
  323.             *ncseg; /* Num of segs in set of segs that have same tag number */
  324.  
  325.         complex double *y11a, /* Self admittance of segments */
  326.             *y12a;            /* Mutual admittances stored in order 1,2 1,3 2,3 2,4 etc */
  327.  
  328. } yparm_t;
  329.  
  330. /* common  /zload/ */
  331. typedef struct
  332. {
  333.         int nload; /* Number of loading networks */
  334.  
  335.         complex double *zarray; /* = Zi/(Di/lambda) */
  336.  
  337. } zload_t;
  338.  
  339. /* Returns the complex double of the arguments */
  340. #define cmplx(r, i) ((r) + (i) *CPLX_01)
  341.  
  342. /*------------------------------------------------------------------------*/
  343.  
  344. /* Function prototypes produced by cproto */
  345. /* calculations.c */
  346. void cabc (complex double *curx);
  347. void couple (complex double *cur, double wlam);
  348. void load (
  349.     int *ldtyp, int *ldtag, int *ldtagf, int *ldtagt, double *zlr, double *zli, double *zlc);
  350. void gf (double zk, double *co, double *si);
  351. double db10 (double x);
  352. double db20 (double x);
  353. void intrp (
  354.     double x,
  355.     double y,
  356.     complex double *f1,
  357.     complex double *f2,
  358.     complex double *f3,
  359.     complex double *f4);
  360. void intx (double el1, double el2, double b, int ij, double *sgr, double *sgi);
  361. int min (int a, int b);
  362. void test (
  363.     double f1r, double f2r, double *tr, double f1i, double f2i, double *ti, double dmin);
  364. void sbf (int i, int is, double *aa, double *bb, double *cc);
  365. void tbf (int i, int icap);
  366. void trio (int j);
  367. void zint (double sigl, double rolam, complex double *zt);
  368. double cang (complex double z);
  369. /* fields.c */
  370. void efld (double xi, double yi, double zi, double ai, int ij);
  371. void eksc (
  372.     double s,
  373.     double z,
  374.     double rh,
  375.     double xk,
  376.     int ij,
  377.     complex double *ezs,
  378.     complex double *ers,
  379.     complex double *ezc,
  380.     complex double *erc,
  381.     complex double *ezk,
  382.     complex double *erk);
  383. void ekscx (
  384.     double bx,
  385.     double s,
  386.     double z,
  387.     double rhx,
  388.     double xk,
  389.     int ij,
  390.     int inx1,
  391.     int inx2,
  392.     complex double *ezs,
  393.     complex double *ers,
  394.     complex double *ezc,
  395.     complex double *erc,
  396.     complex double *ezk,
  397.     complex double *erk);
  398. void gh (double zk, double *hr, double *hi);
  399. void gwave (
  400.     complex double *erv,
  401.     complex double *ezv,
  402.     complex double *erh,
  403.     complex double *ezh,
  404.     complex double *eph);
  405. void gx (double zz, double rh, double xk, complex double *gz, complex double *gzp);
  406. void gxx (
  407.     double zz,
  408.     double rh,
  409.     double a,
  410.     double a2,
  411.     double xk,
  412.     int ira,
  413.     complex double *g1,
  414.     complex double *g1p,
  415.     complex double *g2,
  416.     complex double *g2p,
  417.     complex double *g3,
  418.     complex double *gzp);
  419. void hfk (double el1, double el2, double rhk, double zpkx, double *sgr, double *sgi);
  420. void hintg (double xi, double yi, double zi);
  421. void hsfld (double xi, double yi, double zi, double ai);
  422. void hsflx (
  423.     double s,
  424.     double rh,
  425.     double zpx,
  426.     complex double *hpk,
  427.     complex double *hps,
  428.     complex double *hpc);
  429. void nefld (
  430.     double xob,
  431.     double yob,
  432.     double zob,
  433.     complex double *ex,
  434.     complex double *ey,
  435.     complex double *ez);
  436. void nfpat (void);
  437. void nhfld (
  438.     double xob,
  439.     double yob,
  440.     double zob,
  441.     complex double *hx,
  442.     complex double *hy,
  443.     complex double *hz);
  444. void pcint (
  445.     double xi,
  446.     double yi,
  447.     double zi,
  448.     double cabi,
  449.     double sabi,
  450.     double salpi,
  451.     complex double *e);
  452. void unere (double xob, double yob, double zob);
  453. /* geometry.c */
  454. void arc (int itg, int ns, double rada, double ang1, double ang2, double rad);
  455. void conect (int ignd);
  456. void datagn (void);
  457. void helix (
  458.     double s,
  459.     double hl,
  460.     double a1,
  461.     double b1,
  462.     double a2,
  463.     double b2,
  464.     double rad,
  465.     int ns,
  466.     int itg);
  467. int isegno (int itagi, int mx);
  468. void move (
  469.     double rox,
  470.     double roy,
  471.     double roz,
  472.     double xs,
  473.     double ys,
  474.     double zs,
  475.     int its,
  476.     int nrpt,
  477.     int itgi);
  478. void patch (
  479.     int nx,
  480.     int ny,
  481.     double ax1,
  482.     double ay1,
  483.     double az1,
  484.     double ax2,
  485.     double ay2,
  486.     double az2,
  487.     double ax3,
  488.     double ay3,
  489.     double az3,
  490.     double ax4,
  491.     double ay4,
  492.     double az4);
  493. void subph (int nx, int ny);
  494. void readgm (
  495.     char *gm,
  496.     int *i1,
  497.     int *i2,
  498.     double *x1,
  499.     double *y1,
  500.     double *z1,
  501.     double *x2,
  502.     double *y2,
  503.     double *z2,
  504.     double *rad);
  505. void reflc (int ix, int iy, int iz, int itx, int nop);
  506. void wire (
  507.     double xw1,
  508.     double yw1,
  509.     double zw1,
  510.     double xw2,
  511.     double yw2,
  512.     double zw2,
  513.     double rad,
  514.     double rdel,
  515.     double rrad,
  516.     int ns,
  517.     int itg);
  518. /* ground.c */
  519. void rom2 (double a, double b, complex double *sum, double dmin);
  520. void sflds (double t, complex double *e);
  521. /* input.c */
  522. void qdsrc (int is, complex double v, complex double *e);
  523. void readmn (
  524.     char *gm,
  525.     int *i1,
  526.     int *i2,
  527.     int *i3,
  528.     int *i4,
  529.     double *f1,
  530.     double *f2,
  531.     double *f3,
  532.     double *f4,
  533.     double *f5,
  534.     double *f6);
  535. /* main.c */
  536. int main (int argc, char **argv);
  537. void Null_Pointers (void);
  538. void prnt (
  539.     int in1,
  540.     int in2,
  541.     int in3,
  542.     double fl1,
  543.     double fl2,
  544.     double fl3,
  545.     double fl4,
  546.     double fl5,
  547.     double fl6,
  548.     char *ia,
  549.     int ichar);
  550. /* matrix.c */
  551. void cmset (int nrow, complex double *cm, double rkhx, int iexkx);
  552. void cmss (int j1, int j2, int im1, int im2, complex double *cm, int nrow, int itrp);
  553. void cmsw (
  554.     int j1,
  555.     int j2,
  556.     int i1,
  557.     int i2,
  558.     complex double *cm,
  559.     complex double *cw,
  560.     int ncw,
  561.     int nrow,
  562.     int itrp);
  563. void cmws (
  564.     int j, int i1, int i2, complex double *cm, int nr, complex double *cw, int nw, int itrp);
  565. void cmww (
  566.     int j, int i1, int i2, complex double *cm, int nr, complex double *cw, int nw, int itrp);
  567. void etmns (
  568.     double p1,
  569.     double p2,
  570.     double p3,
  571.     double p4,
  572.     double p5,
  573.     double p6,
  574.     int ipr,
  575.     complex double *e);
  576. void factr (int n, complex double *a, int *ip, int ndim);
  577. void factrs (int np, int nrow, complex double *a, int *ip);
  578. void fblock (int nrow, int ncol, int imax, int ipsym);
  579. void solve (int n, complex double *a, int *ip, complex double *b, int ndim);
  580. void solves (
  581.     complex double *a,
  582.     int *ip,
  583.     complex double *b,
  584.     int neq,
  585.     int nrh,
  586.     int np,
  587.     int n,
  588.     int mp,
  589.     int m);
  590. /* misc.c */
  591. void usage (void);
  592. void abort_on_error (int why);
  593. void secnds (double *x);
  594. int stop (int flag);
  595. int load_line (char *buff, FILE *pfile);
  596. void mem_alloc (void **ptr, long int req);
  597. void mem_realloc (void **ptr, long int req);
  598. void free_ptr (void **ptr);
  599. /* network.c */
  600. void netwk (complex double *cm, int *ip, complex double *einc);
  601. /* radiation.c */
  602. void ffld (double thet, double phi, complex double *eth, complex double *eph);
  603. void fflds (
  604.     double rox,
  605.     double roy,
  606.     double roz,
  607.     complex double *scur,
  608.     complex double *ex,
  609.     complex double *ey,
  610.     complex double *ez);
  611. void gfld (
  612.     double rho,
  613.     double phi,
  614.     double rz,
  615.     complex double *eth,
  616.     complex double *epi,
  617.     complex double *erd,
  618.     complex double ux,
  619.     int ksymp);
  620. void rdpat (void);
  621. /* somnec.c */
  622. void somnec (double epr, double sig, double fmhz);
  623. void bessel (complex double z, complex double *j0, complex double *j0p);
  624. void evlua (
  625.     complex double *erv, complex double *ezv, complex double *erh, complex double *eph);
  626. void fbar (complex double p, complex double *r);
  627. void gshank (
  628.     complex double start,
  629.     complex double dela,
  630.     complex double *sum,
  631.     int nans,
  632.     complex double *seed,
  633.     int ibk,
  634.     complex double bk,
  635.     complex double delb);
  636. void hankel (complex double z, complex double *h0, complex double *h0p);
  637. void lambda (double t, complex double *xlam, complex double *dxlam);
  638. void rom1 (int n, complex double *sum, int nx);
  639. void saoa (double t, complex double *ans);
  640. #endif
  641.  
  642. /* provide wrapper functions to allow change of the data type for printing */
  643. static inline float print_creall (complex double x)
  644. {
  645.         return (float) creall (x);
  646. };
  647. static inline float print_cimagl (complex double x)
  648. {
  649.         return (float) cimagl (x);
  650. };
  651.