11
extern int optind, opterr;
13
extern struct performance_data max, weight;
14
extern double original_percent;
15
extern double percent;
16
extern double magnitude, phase;
17
extern double Zo; /* Z0 is defined in yagi.h, Zo can be set in optimise */
18
extern double max_gain, boom_factor, diameter, best_perf;
20
extern int iterations, fitness_method;
22
extern double boom_sd, length_sd;
23
extern int K_times, K_times_max;
25
double min_offset_from_peak=0.0;
26
double angular_stepsize_2=0.0;
28
void get_command_line_options(int argc, char **argv, struct flags *flag)
31
/* Since not all complilers come with the 'getopts' functions, I've
32
get a source of it and put it in the distribution of Yagi-Uda.
33
To avoid conflics on unix systems, I've rename it to getoptions */
34
while((c=getoptions(argc,argv,"A:c:kwW:hvdg:Or:P:m:C:b:x:f:s:S:G:R:X:F:l:o:e:Z:p:t:T:K:")) != -1)
37
case 'k': /* To keep the old start point with the GA */
40
case 'C': /* Optimise by making element current the same */
41
flag -> Cflg=atoi(optarg);
43
case 'A': /* Automatically maximise */
44
flag->Aflg=atoi(optarg)+1000;
47
fprintf(stderr,"Aflg x, where (-1<= x<= directors)\n");
51
case 'W': /* weighted inprovement */
52
flag->Wflg=atoi(optarg);
53
if(flag->Wflg <1 || flag->Wflg>64)
55
fprintf(stderr,"-Wx, where x=1(gain),2() etc AND\n");
60
case 'a': /* Angular step size to use when pattern searching */
62
if(!isdigit( (int) *optarg) && *optarg !='.')
64
error_message("Non numeric data entered for option -a which requires numeric data.\n");
67
angular_stepsize_2=atof(optarg);
68
if(angular_stepsize_2 < 0.0)
70
error_message("The '-a' requires a posistive float, signifying the angular stepsize to use when finding sidelobes.\n");
74
case 'P': /* Get average level of pattern down */
76
if(!isdigit( (int) *optarg) && *optarg !='.')
78
error_message("Non numeric data entered for option -P which requires numeric data.\n");
81
weight.sidelobe=atof(optarg);
82
if(weight.sidelobe < 0.0)
84
error_message("The '-P' requires a posistive float, signifying the weight on the sidelobe level (default=1.0).\n");
88
case 'c': /* Get average level of pattern down */
89
if(!isdigit( (int) *optarg) && *optarg !='.')
91
error_message("Non numeric data entered for option -P which requires numeric data.\n");
94
max.sidelobe=atof(optarg);
95
if(max.sidelobe < 0.0)
97
error_message("The '-P' requires a posistive float, signifying the sidelobe level down to aim for in dB (20 is reasonable).\n");
101
case 'm': /* Get minimum deviation from theta=90, to condsider a sidelobe. Higher the gain antenna, the smaller it should be set. */
103
if(!isdigit( (int) *optarg) && *optarg !='.')
105
error_message("Non numeric data entered for option -m which requires numeric data.\n");
108
min_offset_from_peak=atof(optarg);
109
if(min_offset_from_peak < 0.0|| min_offset_from_peak > 90)
111
error_message("The '-m' requires a posistive float, signifying the minimum offset in degrees from theta =90, to start considering a sidelobe, rather than the main beam.\n");
115
case 'w': /* wide band ant wanted - avg at low, design and upper f */
116
flag->wflg=2; /* do at three frequencies, 2 extra ones */
118
case 'r': /* acceptable_resistance_error option */
120
if(!isdigit( (int) *optarg) && *optarg !='.')
122
error_message("Non numeric data entered for option -r which requires numeric data.\n");
128
error_message("The '-r' option setting an acceptable vswr must >=0.0\n");
132
case 'x': /* acceptable_reactance option */
134
if(!isdigit( (int) *optarg) && *optarg !='.')
136
error_message("Non numeric data entered for option -x which requires numeric data.\n");
142
error_message("The '-x' option setting an acceptable reactance must >=0.0\n");
146
case 's': /* acceptable_vswr option */
148
if(!isdigit( (int) *optarg) && *optarg !='.')
150
error_message("Non numeric data entered for option -s which requires numeric data.\n");
153
max.swr=atof(optarg);
156
error_message("The '-s' option setting an acceptable vswr must >= 1.\n");
160
case 'f': /* acceptable_fb_ratio option */
162
if(!isdigit( (int) *optarg) && *optarg !='.')
164
error_message("Non numeric data entered for option -f which requires numeric data.\n");
170
error_message("The '-f' option setting an acceptable FB ratio must >=0.0\n");
174
case 'F': /* fb_ratio weight */
176
if(!isdigit( (int) *optarg) && *optarg !='.')
178
error_message("Non numeric data entered for option -F which requires numeric data.\n");
181
weight.fb=atof(optarg);
184
error_message("The '-F' option setting the weight for FB ratio must >=0.0\n");
188
case 'G': /* fb_ratio weight */
190
if(!isdigit( (int) *optarg) && *optarg !='.')
192
error_message("Non numeric data entered for option -G which requires numeric data.\n");
195
weight.gain=atof(optarg);
196
if(weight.gain < 0.0)
198
error_message("The '-G' option setting the weight for gain must >=0.0\n");
202
case 'S': /* weight of swr*/
204
if(!isdigit( (int) *optarg) && *optarg !='.')
206
error_message("Non numeric data entered for option -S which requires numeric data.\n");
209
weight.swr=atof(optarg);
212
error_message("The '-S' option setting the weight for swr must >=0.0\n");
216
case 'l': /* percentage change in ele positions */
218
if(!isdigit( (int) *optarg) && *optarg !='.'&& *optarg!='-')
220
error_message("Non numeric data entered for option -l which requires numeric data.\n");
223
original_percent=atof(optarg);
225
case 'o': /* optimise for gain, fb etc etc */
226
if(!isdigit( (int) *optarg))
228
error_message("Non numeric data entered for option -o which requires numeric data.\n");
231
flag->oflg=atoi(optarg);
232
if(flag->oflg< 0 || flag->oflg > 128)
234
error_message("The '-o' option setting the parameter(s) to optimise for must be in the range 0 to 128.\n");
241
case 'K': /* Keep to original data, until K bad goes */
243
if(!isdigit( (int) *optarg))
245
error_message("Non numeric data entered for option -K which requires an integer.\n");
248
K_times_max=atoi(optarg);
251
error_message("The '-K' option setting the number of attemps to stay with hte original data after a good one found, to avoid local optimums, must be an integer > 1.\n");
255
case 'b': /* how long can boom be extended */
257
if(!isdigit( (int) *optarg) && *optarg !='.')
259
error_message("Non numeric data entered for option -b which requires numeric data.\n");
262
boom_factor=atof(optarg);
263
if(boom_factor < 0.0)
265
error_message("The '-b' option setting the maximum permissable change in the boom length (in %%) must be >=0.0\n");
269
case 'Z': /* Characteristic impedance */
271
if(!isdigit( (int) *optarg) && *optarg !='.')
273
error_message("Non numeric data entered for option -Z which requires numeric data.\n");
279
error_message("The '-Z' option setting Zo must be > 0.0\n");
283
case 'e': /* type of element moved (driven, parasitic or both) */
284
if(!isdigit( (int) *optarg) )
286
error_message("Non numeric data entered for option -e which requires numeric data.\n");
289
flag->eflg=atoi(optarg);
290
if(flag->eflg < 0 || flag->eflg > 1024)
292
error_message("The '-e' option setting the type of elements moved must be an integer between 1 and 127\n");
296
printf("Thats odd, you dont want to move any elements (-e0 option)\n");
302
printf("version = %f\n", version());
308
flag->gflg=atoi(optarg);
309
if(flag->gflg<1 || flag->gflg>64)
311
fprintf(stderr,"-gx, where x=1 to 64\n");
317
if(!isdigit( (int) *optarg) && *optarg !='.')
319
error_message("Non numeric data entered for option -p which requires numeric data.\n");
322
popsize=atoi(optarg);
323
if(popsize < 2 || popsize > 10000000)
325
error_message("The '-p' option setting the population size of the genetric algorithm, mush be between 2 amd 1000000\n");
331
if(!isdigit( (int) *optarg) && *optarg !='.')
333
error_message("Non numeric data entered for option -t which requires numeric data.\n");
336
length_sd=atof(optarg); /* SD on lengths, in mm */
339
error_message("The '-t' option setting the standard deviation of the element lengths must be > 0\n");
345
if(!isdigit( (int) *optarg) && *optarg !='.')
347
error_message("Non numeric data entered for option -T which requires numeric data.\n");
350
boom_sd=atof(optarg); /* SD on lengths, in mm */
353
error_message("The '-T' option setting the standard deviation of the boom postions must be > 0\n");