Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / create_bmp_for_stripline_coupler.c
1 /* atlc - arbitrary transmission line calculator, for the analysis of
2 transmission lines are directional couplers. 
3
4 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either package_version 2
9 of the License, or (at your option) any later package_version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
19 USA.
20
21 Dr. David Kirkby, e-mail drkirkby at ntlworld.com 
22
23 */
24
25 /* The following calculates the odd and even mode impedances between two
26 zero thickness strips of width w, spaced a distance s between two
27 groundplanes of spacing h. */
28 #include "config.h"
29
30
31 #define RATIO 8
32 #include "definitions.h"
33 #include "exit_codes.h"
34
35 #ifdef HAVE_STDLIB_H
36 #include <stdlib.h>
37 #endif
38
39 #ifdef HAVE_STRING_H
40 #include <string.h>
41 #endif
42
43 double WW, HH, ww, Er1, Er2;
44 static double ss; 
45 int W, H, s,  w,  verbose=FALSE;
46
47 int main(int argc, char **argv)
48 {
49   double er, return_error;
50   double Zodd, Zeven, Zo;
51   int bmp_size=DEFAULT_COUPLER_BMP_SIZE, q; 
52   FILE *image_data_fp;
53   struct transmission_line_properties optimise;
54   struct transmission_line_properties not_used;
55
56   not_used.W=1; /* keep MipsPro compiler happy on IRIX */
57
58   while((q=get_options(argc,argv,"Cb:v")) != -1)
59   switch (q) 
60   {
61     case 'C':
62       print_copyright((char *) "2002");
63       exit_with_msg_and_exit_code("",OKAY);
64     break;
65     case 'b':
66       bmp_size=atol(my_optarg); 
67     break;
68     case 'v':
69       verbose++;
70     break;
71   }
72   if( bmp_size < 6 || (argc-my_optind != 5) || bmp_size>28)
73   {
74     usage_create_bmp_for_stripline_coupler();
75     exit_with_msg_and_exit_code("",PROGRAM_CALLED_WITH_WRONG_NUMBER_OF_ARGUMENTS);
76   }
77   HH=atof(argv[my_optind]);
78   ww=atof(argv[my_optind+1]);
79   ss=atof(argv[my_optind+2]);
80   if(HH<0 || ww <0 || ss<0)
81   {
82     fprintf(stderr,"Sorry, W, H and s must all be greater than 0\n");
83     exit_with_msg_and_exit_code("",DIMENSION_LESS_THAN_ZERO);
84   }
85   er=atof(argv[my_optind+3]);
86   Er1=er;
87   Er2=er;
88   if(er < 1.0)
89   {
90     fprintf(stderr,"Sorry, you can't have a dielectric constand Er of less than 1.0\n");
91     exit_with_msg_and_exit_code("Sorry, you can't have a dielectric constand Er of less than 1.0",PERMITTIVITY_LESS_THAN_1);
92   }
93   if( (image_data_fp=fopen(argv[my_optind+4],"wb")) ==NULL)
94     exit_with_msg_and_exit_code("Can't open binary file for writing",CANT_OPEN_FOR_WRITING);
95   WW=2.0*ww+ss+RATIO*HH;
96   optimise.float_values[0]=WW            ;   /* minimum width as a float*/
97   optimise.float_values[1]=HH;               /* height in floats */
98   optimise.float_values[2]=ww;               /* stripline width */
99   optimise.float_values[3]=ss;               /* spacing between the strips */
100
101   optimise.importance[0]=NOT_IMPORTANT;      /* W is non critical */
102   optimise.importance[1]=MOST_IMPORTANT;          /* H is critical */
103   optimise.importance[2]=IMPORTANT;          /* w is critical */
104   optimise.importance[3]=IMPORTANT;     /* s is most critical */
105
106   optimise.odd_or_even[0]=DONT_CARE;        /* W can be odd or even */
107   optimise.odd_or_even[1]=ODD;              /* H must be even */
108   optimise.odd_or_even[2]=DONT_CARE;        /* w can be odd or even */
109   optimise.odd_or_even[3]=DONT_CARE;        /* s can be odd or even */
110
111   /* We will now optimise for the 4 parameters W, H, w and s, forcing H
112   to be odd, and not bothering what the width is, as long as its about
113   right. */
114
115   return_error=calculate_integer_values(&optimise, 4, bmp_size);
116   if(verbose >=2)
117     printf("error returned from calculate_integer_values=%g\n", return_error);
118   W=optimise.best[0];
119   H=optimise.best[1];
120   w=optimise.best[2];
121   s=optimise.best[3];
122   write_bitmap(image_data_fp, not_used);
123   if(verbose >= 1)
124   {
125     calculate_Zodd_and_Zeven(&Zodd, &Zeven, &Zo, ww, HH, ss, er);
126     printf("The actual dimensions you gave have theoretical imedances of:\n");
127     printf("        Zodd= %f Zeven= %f Zo= %f (Ohms) ww=%f HH=%f ss=%f er=%f\n\n", Zodd, Zeven, Zo,ww,HH,ss,er);
128     calculate_Zodd_and_Zeven(&Zodd, &Zeven, &Zo, (double) w, (double) H-10, (double) s, er);
129     printf("The bitmap produced (which approximates what you want) should have:\n");
130     printf("   Zodd= %f Zeven= %f Zo= %f (Ohms)\n", Zodd, Zeven, Zo);
131   }
132   return(OKAY);
133 }