X-Git-Url: https://git.gag.com/?p=debian%2Fatlc;a=blobdiff_plain;f=src%2Fsetup_arrays.c;fp=src%2Fsetup_arrays.c;h=2d7542ec8d84047ee420d3e31a380b6c656a595d;hp=0000000000000000000000000000000000000000;hb=ec2d2ab8e90a0c4b86ffc2385655c2fb27fcacd9;hpb=795fb988211df268a8f7724bd2f4493c594abee9 diff --git a/src/setup_arrays.c b/src/setup_arrays.c new file mode 100644 index 0000000..2d7542e --- /dev/null +++ b/src/setup_arrays.c @@ -0,0 +1,232 @@ +/* atlc - arbitrary transmission line calculator, for the analysis of +transmission lines are directional couplers. + +Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB). + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either package_version 2 +of the License, or (at your option) any later package_version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +USA. + +Dr. David Kirkby, e-mail drkirkby at gmail.com + +*/ +#include "config.h" + + +#ifdef HAVE_STDLIB_H +#include +#endif + +#include "definitions.h" +#include "exit_codes.h" +#include "Erdata.h" + +/* We need to set up the permittivity and cell_type arrays. A +complication arrises if a diaectric is found, that is not vacuum. +If it is the only dielectric found, we calaculate C by saying C=C*Er. If +there are more than one dielectric, we need to calculate it twice. */ + +extern struct pixels Er_in_bitmap[MAX_DIFFERENT_PERMITTIVITIES]; +extern struct pixels Er_on_command_line[MAX_DIFFERENT_PERMITTIVITIES]; +extern int width, height; + +extern double **Vij, **Er; +extern unsigned char *image_data; +extern unsigned char **cell_type; +extern int non_vacuum_found; +extern int coupler; +extern char *inputfile_name; + +void setup_arrays(struct transmission_line_properties *data) +{ + struct pixels pixels_found; + int conductor_found; + int conductors = 0; + int w,h, offset=-3, colour_mixture, i, z; + unsigned char red, green, blue; + int dielectric_found; + int new_colour_in_image; + data->dielectrics_in_bitmap=0; + pixels_found.red=0; + pixels_found.green=0; + pixels_found.blue=0; + pixels_found.white=0; + pixels_found.other_colour=0; + + for(h=0;hcouplerQ=TRUE; + } + else /* A dielectric */ + { + if(colour_mixture == 0xffffff ) /* White */ + pixels_found.white++; /* Vacuum */ + else + pixels_found.other_colour++; /* Some other dielectric */ + cell_type[w][height-1-h]=DIELECTRIC; + Vij[w][height-1-h]=0.0; /* XXXXXXXXXXx */ + for(z=0;zfound_this_dielectric=Ers[z]; + } + } + } + for(i=0;idielectrics_on_command_line;++i) + { + if (Er_on_command_line[i].other_colour == colour_mixture) + { + Er[w][height-1-h]=Er_on_command_line[i].epsilon; + dielectric_found=TRUE; + data->found_this_dielectric=Er_on_command_line[i].epsilon; + non_vacuum_found=TRUE; + } + } + } + if((dielectric_found == FALSE) && (conductor_found==FALSE)) + { + 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); + fprintf(stderr,"However, atlc does not know how to interpret this colour. This is not a\n"); + fprintf(stderr,"conductor (pure red, green or blue), nor is it one of the %d dielectrics that\n",NUMBER_OF_DIELECTRICS_DEFINED); + fprintf(stderr,"are predefined in Erdata.h, nor is a corresponding dielectric constant defined\n"); + fprintf(stderr,"on the command line with the -d option. Sometimes this occurs when a\n"); + fprintf(stderr,"graphics package is used to make the bitmap, but it performs some form of\n"); + fprintf(stderr,"anti-aliasing or smooting. If this is the case, redraw the image turning such\n"); + fprintf(stderr,"options off. If this is not the case then re-run atlc adding the -d option\n"); + fprintf(stderr,"to define the relative permittivity of the dielectric\n\n"); + fprintf(stderr,"e.g. atlc -d %02x%02x%02x=1.9 %s \n\n",red,green,blue, inputfile_name); + fprintf(stderr,"if this colour has a permittivity of 1.9. If there are multiple undefined\n"); + fprintf(stderr,"dielectrics, then there will need to be multiple copies of the -d option given.\n"); + exit_with_msg_and_exit_code("",UNDEFINED_COLOUR_IN_BITMAP); + } + /* We need to keep a record of the number of dielectrics in the image, + and determine if they are defined on the command line, or if they are + defined on in the header file. */ + if (dielectric_found == TRUE) + { + new_colour_in_image=TRUE; + for (i=0; i< data->dielectrics_in_bitmap; ++i) + { + if (Er_in_bitmap[i].other_colour == colour_mixture) /* a known colour */ + { + new_colour_in_image=FALSE; + if(colour_mixture != 0xffffff) + { + non_vacuum_found=TRUE; + } + } + } + if(new_colour_in_image==TRUE) + { + (data->dielectrics_in_bitmap)++; + Er_in_bitmap[i].other_colour=colour_mixture; + Er_in_bitmap[i].red=red; + Er_in_bitmap[i].green=green; + Er_in_bitmap[i].blue=blue; + Er_in_bitmap[i].epsilon=Er[w][height-1-h]; + } + } /* end of if dielctric found */ + } /* end of for w */ + } /*end of for h */ + /* The following prints a lot of data that is generally not wanted + but is when finding statistics of performance etc. */ + if(data->verbose_level >=3) + { + printf("Red (+1 V conductor) pixels found = %8d \n",pixels_found.red); + printf("Green (0 V conductor) pixels found = %8d \n",pixels_found.green); + printf("Blue (-1 V conductor) pixels found = %8d \n",pixels_found.blue); + printf("White (vacuum dielectric) pixels found = %8d \n",pixels_found.white); + printf("Others (not vacuum dielectic) pixels found = %8d \n",pixels_found.other_colour); + printf("Width = %8d \n",width); + printf("Height = %8d \n",height); + printf("Pixels = %8d \n",width*height); + printf("Number of Dielectrics found = %8d \n", data->dielectrics_in_bitmap); + data->non_metallic_pixels=width*height-pixels_found.red-pixels_found.green -pixels_found.blue; + printf("Number of non-metallic pixels = %8d \n", data->non_metallic_pixels); + printf("filename = %30s \n",inputfile_name); + if (pixels_found.red > 0 ) + conductors+=1; + if (pixels_found.green > 0 ) + conductors+=1; + if (pixels_found.blue > 0 ) + conductors+=1; + printf("Number of Conductors = %d \n", conductors); + } + /* The following should not be necessary, but may be as a test */ + /* I'd like to Miguel Berg for noticcing a servere bug, where the + indeces of w and h were transposed, leading to crashes on Windoze + XP */ + for(h=0;h 1.0) || (Vij[w][h]<-1.0)) + { + fprintf(stderr,"Sorry, something is wrong Vij[%d][%d]=%f in %s %d\n",w,h,Vij[w][h], __FILE__,__LINE__); + exit_with_msg_and_exit_code("Exiting ....",VOLTAGE_OUT_OF_RANGE); + } + } + } + /* Check two conductors and not next to each other, creating a short */ + check_for_shorts(); +} /* end of function */