1 /* atlc - arbitrary transmission line calculator, for the analysis of
2 transmission lines are directional couplers.
4 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
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.
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.
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,
21 Dr. David Kirkby, e-mail drkirkby at ntlworld.com
25 /* The function setup_arrays sets the type of a pixel to be dielectric,
26 or metal. This routines refines that, setting the type of a pixel to be
27 some number between 1 and 28 according to where it is located, and what
28 is around it. See Green paper to understand what they mean */
31 #include "definitions.h"
32 #include "exit_codes.h"
34 extern int width, height;
35 extern unsigned char **cell_type, **oddity;
42 void set_oddity_value(void)
45 double er, ERa, ERb, ERl, ERr;
49 /* Its easier to set the endge values first, as it
50 reduces the amount of checking needed in the main body.
51 There are only 11 cases here - 3 types of metal,
52 the four corners, and the four sides */
54 for(i=0;i<width; ++i) {
55 for(j=0;j<height;++j) {
57 oddity[i][j]=UNDEFINED_ODDITY; /* Stick it to some underfined status */
59 c=cell_type[i][j]; /* Cell type at point (i,j) */
62 /* The 3 metal cases can be quickly checked and the
63 oddity value assigned to a fixed value depending on
64 whether it's -1, 0 or +1 V */
66 if(c <= CONDUCTOR_PLUS_ONE_V ) /* a metal */
70 /* Now do the 4 courners */
71 else if( (i == 0) && (j == height-1) )
72 oddity[i][j]=BOTTOM_LEFT_CORNER;
74 else if ( (i == width-1) && (j == height-1) )
75 oddity[i][j]=BOTTOM_RIGHT_CORNER;
77 else if( (i == 0) && (j == 0) )
78 oddity[i][j]=TOP_LEFT_CORNER;
80 else if( (i == width-1) && (j == 0) )
81 oddity[i][j]=TOP_RIGHT_CORNER;
83 /* Now the four edges */
85 oddity[i][j]=ORDINARY_POINT_LEFT_EDGE;
88 oddity[i][j]=ORDINARY_POINT_TOP_EDGE;
90 else if ( j == height-1)
91 oddity[i][j]=ORDINARY_POINT_BOTTOM_EDGE;
93 else if ( i == width-1 )
94 oddity[i][j]=ORDINARY_POINT_RIGHT_EDGE;
97 else if ( (i == 0 || i == width-1 || j == 0 || j == height-1 ) && (oddity[i][j]==UNDEFINED_ODDITY)) {
98 fprintf(stderr,"Internal error: one of the edge points (%d,%d) is still undefined\n",i,j);
99 fprintf(stderr, "ZZZZZZZZZZZZZ width=%d height=%d\n", width, height);
100 fprintf(stderr,"Error set_oddity_value.c\n");
101 exit(INTERNAL_ERROR);
103 } /* end of for(j=0;j<height-0;++j) { */
104 } /* end of for(i=0;i<width-0; ++i) { */
105 /* With the oddity values of all the edges now know, the centre
106 values can be attempted */
108 for(i=1;i<width-1; ++i) {
109 for(j=1;j<height-1;++j) {
111 c=cell_type[i][j]; /* Cell type at point (i,j) */
112 cl=cell_type[i-1][j]; /* Cell type to left of point (i,j) */
113 cr=cell_type[i+1][j]; /* Cell type to right of point (i,j) */
114 ca=cell_type[i][j-1]; /* Cell type above point (i,j) */
115 cb=cell_type[i][j+1]; /* Cell type below point (i,j) */
124 /* If the conductor is at a fixed voltage, it must stay there
125 so there is nothing to do with it */
127 if(c == CONDUCTOR_ZERO_V )
128 oddity[i][j] = CONDUCTOR_ZERO_V;
130 else if(c== CONDUCTOR_PLUS_ONE_V)
131 oddity[i][j] = CONDUCTOR_PLUS_ONE_V;
133 else if(c == CONDUCTOR_MINUS_ONE_V )
134 oddity[i][j] = CONDUCTOR_MINUS_ONE_V;
136 else if ( cr <= CONDUCTOR_PLUS_ONE_V && cb<= CONDUCTOR_PLUS_ONE_V)
137 oddity[i][j]= METAL_BELOW_AND_RIGHT;
139 else if ( cr <= CONDUCTOR_PLUS_ONE_V && ca<= CONDUCTOR_PLUS_ONE_V)
140 oddity[i][j]= METAL_ABOVE_AND_RIGHT;
142 else if ( cl <= CONDUCTOR_PLUS_ONE_V && cb<= CONDUCTOR_PLUS_ONE_V)
143 oddity[i][j]= METAL_BELOW_AND_LEFT;
145 else if ( cl <= CONDUCTOR_PLUS_ONE_V && ca<= CONDUCTOR_PLUS_ONE_V)
146 oddity[i][j]= METAL_ABOVE_AND_LEFT;
148 else if ( ca <= CONDUCTOR_PLUS_ONE_V )
149 oddity[i][j]= METAL_ABOVE;
151 else if ( cb <= CONDUCTOR_PLUS_ONE_V )
152 oddity[i][j]= METAL_BELOW;
154 else if ( cl <= CONDUCTOR_PLUS_ONE_V )
155 oddity[i][j]= METAL_LEFT;
157 else if ( cr <= CONDUCTOR_PLUS_ONE_V )
158 oddity[i][j]= METAL_RIGHT;
160 else if ( ERb != ERa)
161 oddity[i][j]= DIFFERENT_DIELECTRIC_VERTICALLY;
163 else if ( ERl != ERr )
164 oddity[i][j]= DIFFERENT_DIELECTRIC_HORIZONTALLY;
166 else if ( ERa != er && ERr != er)
167 oddity[i][j]= DIFFERENT_DIELECTRIC_ABOVE_AND_RIGHT;
169 else if ( ERa != er && ERl != er)
170 oddity[i][j]= DIFFERENT_DIELECTRIC_ABOVE_AND_LEFT;
172 else if ( ERb != er && ERl != er)
173 oddity[i][j]= DIFFERENT_DIELECTRIC_BELOW_AND_LEFT;
175 else if ( ERa != er )
176 oddity[i][j]= DIFFERENT_DIELECTRIC_ABOVE;
178 else if ( ERb != er )
179 oddity[i][j]= DIFFERENT_DIELECTRIC_BELOW;
180 else if ( ERl != er )
181 oddity[i][j]= DIFFERENT_DIELECTRIC_LEFT;
183 else if ( ERr != er )
184 oddity[i][j]= DIFFERENT_DIELECTRIC_RIGHT;
187 oddity[i][j]= ORDINARY_INTERIOR_POINT;
188 }/* end of for i=0 to width-1 */
189 } /* end of for j= 0 to height-1 */