Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / set_oddity_from_Greens_paper.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 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 */
29
30 #include "config.h"
31 #include "definitions.h"
32 #include "exit_codes.h"
33
34 extern int width, height;
35 extern unsigned char **cell_type, **oddity;
36 extern double **Er;
37
38 #ifdef HAVE_STDLIB_H
39 #include <stdlib.h>
40 #endif
41
42 void set_oddity_value(void) 
43 {
44   int i, j;
45   double er, ERa, ERb, ERl, ERr;
46   int cl, cr, ca, cb;
47   unsigned char c; 
48
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 */
53
54   for(i=0;i<width; ++i) {
55     for(j=0;j<height;++j) {  
56
57       oddity[i][j]=UNDEFINED_ODDITY;  /* Stick it to some underfined status  */
58
59       c=cell_type[i][j];   /* Cell type at point (i,j) */
60
61
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 */
65
66       if(c <= CONDUCTOR_PLUS_ONE_V ) /* a metal */
67         oddity[i][j]=c;    
68
69
70       /* Now do the 4 courners */
71       else if( (i == 0) && (j ==  height-1)  ) 
72         oddity[i][j]=BOTTOM_LEFT_CORNER;
73
74       else if ( (i == width-1) && (j == height-1)  )  
75         oddity[i][j]=BOTTOM_RIGHT_CORNER;
76
77       else if( (i == 0) && (j == 0) ) 
78         oddity[i][j]=TOP_LEFT_CORNER;
79
80       else if( (i == width-1) && (j == 0)  )
81         oddity[i][j]=TOP_RIGHT_CORNER;
82
83       /* Now the four edges */ 
84       else if ( i == 0 )
85         oddity[i][j]=ORDINARY_POINT_LEFT_EDGE;
86
87       else if ( j == 0 ) 
88         oddity[i][j]=ORDINARY_POINT_TOP_EDGE;
89
90       else if ( j == height-1) 
91         oddity[i][j]=ORDINARY_POINT_BOTTOM_EDGE;
92
93       else if ( i == width-1 ) 
94         oddity[i][j]=ORDINARY_POINT_RIGHT_EDGE;
95
96
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);
102       }
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 */
107
108   for(i=1;i<width-1; ++i) {
109     for(j=1;j<height-1;++j) {  
110
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) */
116
117       ERa=Er[i][j-1];
118       ERb=Er[i][j+1];
119       ERl=Er[i-1][j];
120       ERr=Er[i+1][j];
121       er=Er[i][j];
122
123
124       /* If the conductor is at a fixed voltage, it must stay there
125       so there is nothing to do with it */
126
127       if(c == CONDUCTOR_ZERO_V )
128         oddity[i][j] = CONDUCTOR_ZERO_V;
129
130       else if(c== CONDUCTOR_PLUS_ONE_V)
131         oddity[i][j] = CONDUCTOR_PLUS_ONE_V;
132
133       else if(c == CONDUCTOR_MINUS_ONE_V )
134         oddity[i][j] = CONDUCTOR_MINUS_ONE_V; 
135
136       else if ( cr <= CONDUCTOR_PLUS_ONE_V && cb<= CONDUCTOR_PLUS_ONE_V)
137         oddity[i][j]= METAL_BELOW_AND_RIGHT;
138
139       else if ( cr <= CONDUCTOR_PLUS_ONE_V && ca<= CONDUCTOR_PLUS_ONE_V)
140         oddity[i][j]= METAL_ABOVE_AND_RIGHT;
141
142       else if ( cl <= CONDUCTOR_PLUS_ONE_V && cb<= CONDUCTOR_PLUS_ONE_V)
143         oddity[i][j]= METAL_BELOW_AND_LEFT;
144
145       else if ( cl <= CONDUCTOR_PLUS_ONE_V && ca<= CONDUCTOR_PLUS_ONE_V)
146         oddity[i][j]= METAL_ABOVE_AND_LEFT;
147
148       else if ( ca <= CONDUCTOR_PLUS_ONE_V )
149         oddity[i][j]= METAL_ABOVE;
150
151       else if ( cb <= CONDUCTOR_PLUS_ONE_V )
152         oddity[i][j]= METAL_BELOW;
153
154       else if ( cl <= CONDUCTOR_PLUS_ONE_V )
155         oddity[i][j]= METAL_LEFT;
156
157       else if ( cr <= CONDUCTOR_PLUS_ONE_V )
158         oddity[i][j]= METAL_RIGHT;
159
160       else if ( ERb != ERa)
161         oddity[i][j]= DIFFERENT_DIELECTRIC_VERTICALLY; 
162  
163       else if ( ERl != ERr )
164         oddity[i][j]= DIFFERENT_DIELECTRIC_HORIZONTALLY;      
165 /*
166       else if ( ERa != er  && ERr != er)
167         oddity[i][j]= DIFFERENT_DIELECTRIC_ABOVE_AND_RIGHT; 
168
169       else if ( ERa != er  && ERl != er)
170         oddity[i][j]= DIFFERENT_DIELECTRIC_ABOVE_AND_LEFT; 
171
172       else if ( ERb != er  && ERl != er)
173         oddity[i][j]= DIFFERENT_DIELECTRIC_BELOW_AND_LEFT; 
174
175       else if ( ERa != er )
176         oddity[i][j]= DIFFERENT_DIELECTRIC_ABOVE; 
177
178       else if ( ERb != er )
179         oddity[i][j]= DIFFERENT_DIELECTRIC_BELOW; 
180       else if ( ERl != er )
181         oddity[i][j]= DIFFERENT_DIELECTRIC_LEFT; 
182
183       else if ( ERr != er )
184         oddity[i][j]= DIFFERENT_DIELECTRIC_RIGHT; 
185 */
186       else
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 */
190 }
191