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
31 #include "definitions.h"
32 #include "exit_codes.h"
35 /* We need to set up the permittivity and cell_type arrays. A
36 complication arrises if a diaectric is found, that is not vacuum.
37 If it is the only dielectric found, we calaculate C by saying C=C*Er. If
38 there are more than one dielectric, we need to calculate it twice. */
40 extern struct pixels Er_in_bitmap[MAX_DIFFERENT_PERMITTIVITIES];
41 extern struct pixels Er_on_command_line[MAX_DIFFERENT_PERMITTIVITIES];
42 extern int width, height;
44 extern double **Vij, **Er;
45 extern unsigned char *image_data;
46 extern unsigned char **cell_type;
47 extern int non_vacuum_found;
49 extern char *inputfile_name;
51 void setup_arrays(struct transmission_line_properties *data)
53 struct pixels pixels_found;
56 int w,h, offset=-3, colour_mixture, i, z;
57 unsigned char red, green, blue;
59 int new_colour_in_image;
60 data->dielectrics_in_bitmap=0;
65 pixels_found.other_colour=0;
69 for (w=0; w<width;++w)
71 cell_type[w][height-1-h]=0;
72 dielectric_found=FALSE;
73 conductor_found=FALSE;
75 if((w==0) && (offset%4!=0) && (h!=0))
77 if((w==0) && (offset%4!=0) && (h!=0))
79 if((w==0) && (offset%4!=0) && (h!=0))
81 blue=image_data[offset];
82 green=image_data[offset+1];
83 red=image_data[offset+2];
84 colour_mixture=256*256*red+256*green+blue;
85 if( colour_mixture == 0xff0000 ) /* +1V red */
87 cell_type[w][height-1-h]=CONDUCTOR_PLUS_ONE_V;
88 Vij[w][height-1-h]=1.0;
89 Er[w][height-1-h]=METAL_ER;
93 else if( colour_mixture == 0x00ff00 ) /* 0v green */
95 cell_type[w][height-1-h]=CONDUCTOR_ZERO_V;
96 Vij[w][height-1-h]=0.0;
99 Er[w][height-1-h]=METAL_ER;
101 else if( colour_mixture == 0x0000ff ) /* -1V blue */
103 cell_type[w][height-1-h]=CONDUCTOR_MINUS_ONE_V;
104 Vij[w][height-1-h]=-1.0;
105 conductor_found=TRUE;
107 Er[w][height-1-h]=METAL_ER;
111 else /* A dielectric */
113 if(colour_mixture == 0xffffff ) /* White */
114 pixels_found.white++; /* Vacuum */
116 pixels_found.other_colour++; /* Some other dielectric */
117 cell_type[w][height-1-h]=DIELECTRIC;
118 Vij[w][height-1-h]=0.0; /* XXXXXXXXXXx */
119 for(z=0;z<NUMBER_OF_DIELECTRICS_DEFINED;++z)
121 /* Check to see if the colour is one of the 10 known
122 about, without any need to define on the command line
124 if (colour_mixture == colours[z])
126 Er[w][height-1-h]=Ers[z];
127 dielectric_found=TRUE;
130 non_vacuum_found=TRUE;
131 data->found_this_dielectric=Ers[z];
135 for(i=0;i<data->dielectrics_on_command_line;++i)
137 if (Er_on_command_line[i].other_colour == colour_mixture)
139 Er[w][height-1-h]=Er_on_command_line[i].epsilon;
140 dielectric_found=TRUE;
141 data->found_this_dielectric=Er_on_command_line[i].epsilon;
142 non_vacuum_found=TRUE;
146 if((dielectric_found == FALSE) && (conductor_found==FALSE))
148 fprintf(stderr,"Error#7: The colour r=0x%x g=0x%x b=0x%x (0x%02x%02x%02x) exists at pixel %d,%d.\n",red,green,blue,red,green,blue,w,h);
149 fprintf(stderr,"However, atlc does not know how to interpret this colour. This is not a\n");
150 fprintf(stderr,"conductor (pure red, green or blue), nor is it one of the %d dielectrics that\n",NUMBER_OF_DIELECTRICS_DEFINED);
151 fprintf(stderr,"are predefined in Erdata.h, nor is a corresponding dielectric constant defined\n");
152 fprintf(stderr,"on the command line with the -d option. Sometimes this occurs when a\n");
153 fprintf(stderr,"graphics package is used to make the bitmap, but it performs some form of\n");
154 fprintf(stderr,"anti-aliasing or smooting. If this is the case, redraw the image turning such\n");
155 fprintf(stderr,"options off. If this is not the case then re-run atlc adding the -d option\n");
156 fprintf(stderr,"to define the relative permittivity of the dielectric\n\n");
157 fprintf(stderr,"e.g. atlc -d %02x%02x%02x=1.9 %s \n\n",red,green,blue, inputfile_name);
158 fprintf(stderr,"if this colour has a permittivity of 1.9. If there are multiple undefined\n");
159 fprintf(stderr,"dielectrics, then there will need to be multiple copies of the -d option given.\n");
160 exit_with_msg_and_exit_code("",UNDEFINED_COLOUR_IN_BITMAP);
162 /* We need to keep a record of the number of dielectrics in the image,
163 and determine if they are defined on the command line, or if they are
164 defined on in the header file. */
165 if (dielectric_found == TRUE)
167 new_colour_in_image=TRUE;
168 for (i=0; i< data->dielectrics_in_bitmap; ++i)
170 if (Er_in_bitmap[i].other_colour == colour_mixture) /* a known colour */
172 new_colour_in_image=FALSE;
173 if(colour_mixture != 0xffffff)
175 non_vacuum_found=TRUE;
179 if(new_colour_in_image==TRUE)
181 (data->dielectrics_in_bitmap)++;
182 Er_in_bitmap[i].other_colour=colour_mixture;
183 Er_in_bitmap[i].red=red;
184 Er_in_bitmap[i].green=green;
185 Er_in_bitmap[i].blue=blue;
186 Er_in_bitmap[i].epsilon=Er[w][height-1-h];
188 } /* end of if dielctric found */
191 /* The following prints a lot of data that is generally not wanted
192 but is when finding statistics of performance etc. */
193 if(data->verbose_level >=3)
195 printf("Red (+1 V conductor) pixels found = %8d \n",pixels_found.red);
196 printf("Green (0 V conductor) pixels found = %8d \n",pixels_found.green);
197 printf("Blue (-1 V conductor) pixels found = %8d \n",pixels_found.blue);
198 printf("White (vacuum dielectric) pixels found = %8d \n",pixels_found.white);
199 printf("Others (not vacuum dielectic) pixels found = %8d \n",pixels_found.other_colour);
200 printf("Width = %8d \n",width);
201 printf("Height = %8d \n",height);
202 printf("Pixels = %8d \n",width*height);
203 printf("Number of Dielectrics found = %8d \n", data->dielectrics_in_bitmap);
204 data->non_metallic_pixels=width*height-pixels_found.red-pixels_found.green -pixels_found.blue;
205 printf("Number of non-metallic pixels = %8d \n", data->non_metallic_pixels);
206 printf("filename = %30s \n",inputfile_name);
207 if (pixels_found.red > 0 )
209 if (pixels_found.green > 0 )
211 if (pixels_found.blue > 0 )
213 printf("Number of Conductors = %d \n", conductors);
215 /* The following should not be necessary, but may be as a test */
216 /* I'd like to Miguel Berg for noticcing a servere bug, where the
217 indeces of w and h were transposed, leading to crashes on Windoze
219 for(h=0;h<height;h++)
221 for (w=0; w<width;++w)
223 if((Vij[w][h] > 1.0) || (Vij[w][h]<-1.0))
225 fprintf(stderr,"Sorry, something is wrong Vij[%d][%d]=%f in %s %d\n",w,h,Vij[w][h], __FILE__,__LINE__);
226 exit_with_msg_and_exit_code("Exiting ....",VOLTAGE_OUT_OF_RANGE);
230 /* Check two conductors and not next to each other, creating a short */
232 } /* end of function */