Imported Upstream version 4.6.0
[debian/atlc] / tools / src / coax.c
1 /*
2 atlc - arbitrary transmission line calculator, for the analysis of
3 transmission lines are directional couplers. 
4
5 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either package_version 2
10 of the License, or (at your option) any later package_version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
20 USA.
21
22 Dr. David Kirkby, e-mail drkirkby at ntlworld.com 
23
24 */
25
26
27 /* coax finds the properties of a standard coaxial cable - useful as a test for atlc */
28
29 #include "config.h"
30
31 #ifdef HAVE_STDIO_H
32 #include <stdio.h>
33 #endif
34
35 #ifdef HAVE_STDLIB_H
36 #include <stdlib.h>
37 #endif
38
39 #ifdef HAVE_MATH_H
40 #include <math.h>
41 #endif
42
43 #define MU_0 4*M_PI*1e-7
44 #define EPSILON_0 8.854187817e-12 /* Data taken from NPL */
45
46
47 #ifndef PI
48 #define PI 3.141592653589793238462643383279502884197169399375105
49 #endif
50
51 extern int my_optind; 
52 extern char *my_optarg;
53
54 int get_options(int argc, char **argv, const char *opts);
55 void usage_coax();
56
57
58 int main (int argc, char **argv)
59 {
60   double d, D, er, zo, x;
61   double offset=0.0;
62   int q;
63
64
65   while((q=get_options(argc,argv,"O:")) != -1)
66   switch (q) {
67    case 'O':
68      offset=atof(my_optarg);
69    break;
70    case '?':
71     usage_coax();
72    break;
73   }
74   if(argc-my_optind != 3)
75     usage_coax();
76   d=atof(argv[my_optind]);
77   D=atof(argv[my_optind+1]);
78   er=atof(argv[my_optind+2]);
79   if ( d  >=  D){
80     fprintf(stderr,"Sorry, the diameter of the inner conductor (d) must be\n");
81     fprintf(stderr,"less than the inner diameter of the outer conductor (D)\n");
82     exit(1);
83   }
84   if (er < 1.0 ){
85     fprintf(stderr,"Sorry, the permittivity of the dielectric Er must be >=1");
86     exit(1);
87   }
88   if(D/2.0 <= d/2 + offset){
89     fprintf(stderr,"The offset between the inner and outer conductors is too large; the\n");
90     fprintf(stderr,"inner and outer conductors will touch!!\n");
91     exit(1);
92   }
93
94   x=(double) (d*d+D*D-4*offset*offset)/(2*D*d);
95   zo=(1/(2*PI))*sqrt(MU_0)*log(x+sqrt(x*x-1))/sqrt(EPSILON_0*er);
96   printf("Zo = %16f Ohms\n", zo);
97   return(0);
98
99 }