Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / create_bmp_for_symmetrical_stripline.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 program widestrip is a pre-processor for atlc. It produces bitmaps 
26 of a thin strip, between two wide plates */
27 #include "config.h"
28
29 #define RATIO 4           /* W = H*RATIO+w */
30
31 #ifdef HAVE_STDLIB_H
32 #include <stdlib.h>
33 #endif  
34
35 #ifdef HAVE_STRING_H
36 #include <string.h>
37 #endif  
38 #include "definitions.h"
39 #include "exit_codes.h"
40
41 #ifdef WINDOWS
42 #pragma hrdstop
43 #include <condefs.h>
44 #endif
45
46 int verbose=0;
47
48 extern int main(int argc, char **argv) /* Read parameters from command line here   */
49 {
50   int W, H, w, size_of_image, q;
51   int user_requires_effectively_infinite_width=FALSE;
52   double Zo;
53   unsigned char *unaligned_image_vector, *aligned_image_vector;
54   FILE *fp;
55 #ifndef HAVE_MEMSET
56   int memory_location;
57 #endif
58
59   while((q=get_options(argc,argv,"Cvi")) != -1)
60   switch (q) 
61   {
62     case 'C':
63       print_copyright((char *) "2002");
64       exit_with_msg_and_exit_code("",OKAY);
65     break;
66     case 'i':
67       user_requires_effectively_infinite_width=TRUE;
68     break;
69     case 'v':
70       verbose++;
71     break;
72     case '?':
73       usage_create_bmp_for_symmetrical_stripline();
74     break;
75   } /* End of the switch statement */
76   if(argc-my_optind !=4)
77   {
78     usage_create_bmp_for_symmetrical_stripline();    
79     exit_with_msg_and_exit_code("",PROGRAM_CALLED_WITH_WRONG_NUMBER_OF_ARGUMENTS);
80   }
81   W=atoi(argv[my_optind]);
82   H=atoi(argv[my_optind+1])+2*BORDER;
83   if(H%2==0) /* make it odd, so that the inner can sit in the middle */
84   {
85     H++;
86     printf("H needs to be odd, so the inner conductor (1 pixel high) will fit\
87     centrally. Hence H has been increased to %d pixels\n",H);
88   }
89   w=atoi(argv[my_optind+2]);
90   if ((W < RATIO*H + w) && user_requires_effectively_infinite_width==TRUE)
91   {
92     fprintf(stderr,"For this to be a valid test of atlc, the width should be\n");
93     fprintf(stderr,"infinite. Since you used the -i option (indicationg you\n");
94     fprintf(stderr,"want the width W to effectively infinite, W must exceed w + %dxH.\n",RATIO);
95     fprintf(stderr,"Therefore W has been is set to %d\n",RATIO*H+w );
96     W=RATIO*H+w;
97   }
98   if(W <= 5 || H <= 5)
99     exit_with_msg_and_exit_code("W or H is under 6, which is stupid (remember these are pixels !! in this program)",W_OR_H_TOO_SMALL);
100   aligned_image_vector=ustring(0,(W+3)*3*H+100);
101   unaligned_image_vector=ustring(0,(W+3)*3*H+100);
102
103   if((fp=fopen(argv[my_optind+3],"wb")) == NULL)
104   {
105     exit_with_msg_and_exit_code("Error in opening file in create_bmp_for_symmetrical_stripline",CANT_OPEN_FOR_WRITING);
106   }
107   aligned_image_vector=ustring(0,(W+3)*3*H);
108   unaligned_image_vector=ustring(0,(W+3)*3*H);
109
110 #ifdef HAVE_MEMSET
111   (void) memset((void *) (aligned_image_vector),0x00,(size_t) W*H*3);
112 #else
113   for(memory_location=0; memory_location < W*H*3; memory_location++)
114     aligned_image_vector[memory_location]=0;
115 #endif
116
117   /* Fill a vector with */
118   fill_image_vector_for_thin_strip(W,H,w,unaligned_image_vector);
119   size_of_image=align_bitmap_image(W, H, unaligned_image_vector,aligned_image_vector);
120
121   write_bitmap_out(aligned_image_vector, fp, size_of_image, W, H);
122   /* write_bitmap_out closes the file pointer */
123   Zo=calculate_symmetrical_stripline_impedance(H-2*BORDER,w);
124   if(verbose >=1 && W >= RATIO*H + w )
125     printf("Zo is theoretically %f Ohms (assuming W is infinite)\n",Zo);
126   else if (verbose >=1 && W < RATIO*H + w){
127     exit_with_msg_and_exit_code("A theoretical value for Zo can't be computed as the width W is too small",1);
128   }
129   return(OKAY); /* This does not get executed, but keeps the compiler
130   happier, as otherwise it gives a warning about control reaching the
131   end of a non-void function */
132 }