Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / check_for_shorts.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 /* This routines checkes for short circuits in the image. Clearly, it is
26 should not possible to have a 1V conductor touching a -1 V conductor. 
27
28 Although currently the software does not support the use of a floating 
29 conductor (an anea of fixed, but undefined) voltage, error messages
30 to take this into account have been included, but commentted out.*/ 
31
32
33 #include "config.h"
34
35
36 #ifdef HAVE_STDLIB_H
37 #include <stdlib.h>
38 #endif
39
40 #include "definitions.h"
41
42 extern int width, height;
43 extern unsigned char **oddity;
44
45 /* This checks for shorts. We only check to the right (increasing w) and below (increasing h)
46 since its pointless checking all directions when one moves to an adjacent pixel later */
47 void check_for_shorts(void)
48 {
49   int w, h;
50
51   for(h=1;h<height-1;h++)
52   {
53     for(w=1; w<width-1;w++)
54     {
55       if( oddity[w][h]==CONDUCTOR_ZERO_V )
56       {
57         /* Check to see if the pixel below is shorted */       
58         if((oddity[w][h+1]==CONDUCTOR_PLUS_ONE_V) || (oddity[w][h+1]==CONDUCTOR_MINUS_ONE_V) || (oddity[w][h+1]==CONDUCTOR_FLOATING))
59         {
60           fprintf(stderr,"\n**************ERROR******************\n");
61           fprintf(stderr,"Pixel (%d,%d) is set to 0V, but pixel\n",w,h);
62           fprintf(stderr,"(%d,%d) is set to a different fixed voltage\n",w,h+1);
63           fprintf(stderr,"creating a short. Please correct this.\n");
64           exit_with_msg_and_exit_code("",CONDUCTOR_ZERO_V);
65         }
66         /* Check to see if the pixel to the right is shorted */       
67         else if((oddity[w+1][h]==CONDUCTOR_PLUS_ONE_V) || (oddity[w+1][h]==CONDUCTOR_MINUS_ONE_V) || (oddity[w+1][h]==CONDUCTOR_FLOATING))
68         {
69           fprintf(stderr,"\n**************ERROR******************\n");
70           fprintf(stderr,"Pixel (%d,%d) is set to 0V, but pixel\n",w,h);
71           fprintf(stderr,"(%d,%d) is set to a different fixed voltage\n",w+1,h);
72           fprintf(stderr,"creating a short. Please correct this.\n");
73           exit_with_msg_and_exit_code("",CONDUCTOR_ZERO_V);
74         }
75
76       } /* end of if(oddity==CONDUCTOR_ZERO_V) */
77
78       else if( oddity[w][h]==CONDUCTOR_PLUS_ONE_V )
79       {
80         /* Check for a short of the pixel below */        
81         if((oddity[w][h+1]==CONDUCTOR_ZERO_V) || \
82         (oddity[w][h+1]==CONDUCTOR_MINUS_ONE_V) \
83         || (oddity[w][h+1]==CONDUCTOR_FLOATING))
84         {
85           fprintf(stderr,"\n**************ERROR******************\n");
86           fprintf(stderr,"Pixel (%d,%d) is set to 1 V, but pixel\n",w,h);
87           fprintf(stderr,"(%d,%d) is set to a different fixed voltage\n",w,h+1);
88           fprintf(stderr,"creating a short. Please correct this.\n");
89           exit_with_msg_and_exit_code("",CONDUCTOR_PLUS_ONE_V);
90         }
91         /* Check to see if the pixel to the right is shorted */       
92         else if((oddity[w+1][h]==CONDUCTOR_ZERO_V) || \
93         (oddity[w+1][h]==CONDUCTOR_MINUS_ONE_V) \
94         || (oddity[w+1][h]==CONDUCTOR_FLOATING))
95         {
96           fprintf(stderr,"\n**************ERROR******************\n");
97           fprintf(stderr,"Pixel (%d,%d) is set to 1 V, but pixel\n",w,h);
98           fprintf(stderr,"(%d,%d) is set to a different fixed voltage\n",w+1,h);
99           fprintf(stderr,"creating a short. Please correct this.\n");
100           exit_with_msg_and_exit_code("",CONDUCTOR_PLUS_ONE_V);
101         }
102       } /* end of if(oddity==CONDUCTOR_PLUS_ONE_V) */
103       
104       else if( oddity[w][h]==CONDUCTOR_MINUS_ONE_V )
105       {
106         /* Check for a short of the pixel below */        
107         if((oddity[w][h+1]==CONDUCTOR_ZERO_V) || \
108         (oddity[w][h+1]==CONDUCTOR_PLUS_ONE_V) \
109         || (oddity[w][h+1]==CONDUCTOR_FLOATING))
110         {
111           fprintf(stderr,"\n**************ERROR******************\n");
112           fprintf(stderr,"Pixel (%d,%d) is set to -1 V, but pixel\n",w,h);
113           fprintf(stderr,"(%d,%d) is set to a different fixed voltage\n",w,h+1);
114           fprintf(stderr,"creating a short. Please correct this.\n");
115           exit_with_msg_and_exit_code("",CONDUCTOR_MINUS_ONE_V);
116         }
117         /* Check to see if the pixel to the right is shorted */       
118         if((oddity[w][h+1]==CONDUCTOR_ZERO_V) || \
119         (oddity[w][h+1]==CONDUCTOR_PLUS_ONE_V) \
120         || (oddity[w][h+1]==CONDUCTOR_FLOATING))
121         {
122           fprintf(stderr,"\n**************ERROR******************\n");
123           fprintf(stderr,"Pixel (%d,%d) is set to -1 V, but pixel\n",w,h);
124           fprintf(stderr,"(%d,%d) is set to a different fixed voltage\n",w,h+1);
125           fprintf(stderr,"creating a short. Please correct this.\n");
126           exit_with_msg_and_exit_code("",CONDUCTOR_MINUS_ONE_V);
127         }
128       } /* end of if(oddity==CONDUCTOR_PLUS_ONE_V) */
129     } /* end of for w.. loop */
130   } /* end of for h .. loop */
131 } /* end of function check_for_shorts */
132