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 gmail.com
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.
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.*/
40 #include "definitions.h"
42 extern int width, height;
43 extern unsigned char **oddity;
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)
51 for(h=1;h<height-1;h++)
53 for(w=1; w<width-1;w++)
55 if( oddity[w][h]==CONDUCTOR_ZERO_V )
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))
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);
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))
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);
76 } /* end of if(oddity==CONDUCTOR_ZERO_V) */
78 else if( oddity[w][h]==CONDUCTOR_PLUS_ONE_V )
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))
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);
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))
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);
102 } /* end of if(oddity==CONDUCTOR_PLUS_ONE_V) */
104 else if( oddity[w][h]==CONDUCTOR_MINUS_ONE_V )
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))
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);
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))
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);
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 */