~ubuntu-branches/ubuntu/precise/yagiuda/precise

« back to all changes in this revision

Viewing changes to .pc/debian-changes-1.19-6.2/src/input.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2010-08-25 22:19:13 UTC
  • Revision ID: james.westby@ubuntu.com-20100825221913-lgc7yuj3f7nqugpm
Tags: 1.19-7
* QA upload
* Source format 3.0 (quilt)
* patch optopt-declaration: fix declaration of optopt (closes: 593486).
  Thanks a lot to Jakub Wilk <jwilk@debian.org> for the patch!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_STDLIB_H
 
2
#include <stdlib.h>
 
3
#endif
 
4
 
 
5
/* This program, called 'input' asks the user for information about the
 
6
yagi. This includes the number of elements, design frequency, dimension and
 
7
locations of elements.  It also asks for a range of frequencies to plot
 
8
the antenna details over (eg 144-146MHz) and an angular step size (eg 5deg)
 
9
over which the antenna pattern is plotted in both theta and phi (in this case
 
10
0deg, 5deg, 10deg, 15 deg ... 180deg). This program just writes all this
 
11
information into a file, which can be read by 'yagi'. The file created by
 
12
this program has the extension .out and is a text file, so it can be editied 
 
13
manually if required. Be warned though,  'yagi' may not report errors in the
 
14
.out file, so extreme care is necessary if the .out file file is edited
 
15
manually! 
 
16
*/
 
17
 
 
18
#include <stdio.h>
 
19
#include <malloc.h>
 
20
#include <math.h>
 
21
#include "nrutil.h"
 
22
#include "yagi.h"
 
23
 
 
24
extern int optind, opterr;
 
25
 
 
26
int main(int argc, char **argv)
 
27
{
 
28
        double frequency, diameter, **d, **p;
 
29
        double min_f, max_f, step_f, angular_step;
 
30
        int elements, driven, i, fixed_diameter, boom, parasitic, c, hflg=0, errflg=0;
 
31
        double scale_factor;
 
32
        char response, *filename, *notes, *type, data_entry;
 
33
        FILE *fp;
 
34
 
 
35
        filename = string(0L, 1000L);
 
36
        notes = string(0L, 1000L);
 
37
        type = string(0L, 1000L);
 
38
 
 
39
   while ((c =  getoptions(argc,argv,"h")) != -1)
 
40
   switch       (c) 
 
41
   {
 
42
                         case 'h':  /* help */
 
43
                                hflg=1;
 
44
                                break;
 
45
                         case '?':   /*  */
 
46
                                errflg=1;
 
47
                                break;
 
48
        }
 
49
        if(hflg || errflg)
 
50
        {
 
51
                usage_input(argv[0]);
 
52
                exit(0);
 
53
        }
 
54
        printf("Yagi-Uda antenna analysis programs, version %.2f\n", version());
 
55
        printf("Written by Dr. David Kirkby Ph.D. (G8WRB, email:david.kirkby@onetel.net)\n");
 
56
        printf("\nThis program asks for length, diameter and position of antenna elements then\n");
 
57
        printf("writes them to a file you specify. Data is written in m (metres)\n \n");
 
58
        printf("Enter any notes on this design (up to 400 characters): ");
 
59
        gets(notes);
 
60
        printf("Enter a filename to write data to ");
 
61
        gets(filename);
 
62
        printf("Enter the centre frequency in MHz ");
 
63
        scanf("%lf", &frequency);
 
64
        printf("Enter the minimum frequency in MHz ");
 
65
        scanf("%lf", &min_f);
 
66
        printf("Enter the maximum frequency in MHz ");
 
67
        scanf("%lf", &max_f);
 
68
        printf("Enter the frequency steps in MHz ");
 
69
        scanf("%lf", &step_f);
 
70
        if(min_f > frequency)
 
71
                nrerror("The minimum frequency has been set higher than the centre frequency");
 
72
        if(max_f < frequency)
 
73
                nrerror("The maximum frequency has been set lower than the centre frequency");
 
74
        printf("\nData can be entered in imperial (inches) metric (mm) or wavelengths (lambda)\n");
 
75
        printf("Please enter i (for imperial), m (for metric) or w (for wavelengths). ");
 
76
        scanf("%c", &data_entry);
 
77
        scanf("%c", &data_entry);
 
78
        /* The file produced by this is always written in metres.  */
 
79
        if(data_entry=='i' || data_entry=='I')
 
80
        {
 
81
                scale_factor=39.37; /* inches in 1m */
 
82
                type="\"\"";
 
83
        }
 
84
        else if(data_entry=='m' || data_entry=='m')
 
85
        {
 
86
                scale_factor=1000.0; /* mm in 1m */
 
87
                type="mm";
 
88
        }
 
89
        else if(data_entry=='w' || data_entry=='w')
 
90
        {
 
91
                scale_factor=frequency/300; /* wavelegths in 1m */
 
92
                type="lambda";
 
93
        }
 
94
        else
 
95
                exit(1);
 
96
        printf("Enter the number of elements for the antenna ");
 
97
        scanf("%d",&elements);
 
98
        /* printf("Enter the number of driven elements ");
 
99
        scanf("%d", &driven); */
 
100
        driven=1;
 
101
        parasitic=elements-driven;
 
102
        d=dmatrix(1L, (long) driven, 1L, 6L);
 
103
        p=dmatrix(1L, (long) parasitic , 1L, 4L);
 
104
        printf("Enter the angular step size in degrees for the gain to be plotted ");
 
105
        scanf("%lf",&angular_step);
 
106
        /* printf("Are any of the elements tappered? ");
 
107
        scanf("%c", &response);
 
108
        scanf("%c", &response);
 
109
        if(response =='y' || response == 'Y')
 
110
        {
 
111
                tappered=TRUE;
 
112
                printf("\nSorry: this program as yet can't handle tapered elements.\n");
 
113
                exit(1);
 
114
        }
 
115
        */
 
116
        printf("Are all the elements of the same diameter ? ");
 
117
        scanf("%c",&response);
 
118
        scanf("%c",&response);
 
119
        if(response=='Y' || response =='y')
 
120
        {
 
121
                printf("Enter the diameter of the elements (in %s) ", type);
 
122
                scanf("%lf", &diameter);
 
123
                fixed_diameter=TRUE;
 
124
        }
 
125
        else
 
126
                fixed_diameter=FALSE;
 
127
        boom=TRUE;
 
128
        for(i=1;i<=driven;++i) 
 
129
        {
 
130
                printf("\n\nEnter location of the driven element in %s (wrt. reflector at x=0) ", type);
 
131
                scanf("%lf", &d[i][X]);
 
132
                d[i][Y]=0;      
 
133
                if( boom != TRUE)
 
134
                {
 
135
                        printf("Enter the y position of the driven element (in %s) ", type);
 
136
                        scanf("%lf", &d[i][Y]);
 
137
                }
 
138
                else
 
139
                        d[i][Y]=0.0;
 
140
                printf("Enter length of the driven element (in %s) ", type);
 
141
                scanf("%lf", &d[i][LENGTH]);
 
142
                if(fixed_diameter == TRUE)
 
143
                        d[i][DIAMETER]=diameter;
 
144
                else
 
145
                {
 
146
                        printf("Enter the diameter of the driven element (in %s) ", type);
 
147
                        scanf("%lf", &d[i][DIAMETER]);
 
148
                }
 
149
                /*
 
150
                printf("Enter the voltage driving this element ");
 
151
                scanf("%lf", &d[i][VOLTAGE_R]);
 
152
                printf("Enter the phase driving this element ");
 
153
                scanf("%lf", &d[i][VOLTAGE_I]);
 
154
                */
 
155
                d[i][VOLTAGE_R]=1.0;
 
156
                d[i][VOLTAGE_I]=0.0;
 
157
        }
 
158
        for(i=1;i<=elements-driven;++i) 
 
159
        {
 
160
                if(i==1) /* The reflector */
 
161
                {
 
162
                   printf("\nEnter length of the reflector (in %s) ", type);
 
163
                   scanf("%lf", &p[1][LENGTH]);
 
164
                   if(boom != TRUE)
 
165
                   {
 
166
                        printf("\nEnter the y position of the reflector (in %s) ", type);
 
167
                        scanf("%lf", &p[i][Y]);
 
168
                   }
 
169
                   if(fixed_diameter == TRUE)
 
170
                        p[i][DIAMETER]=diameter;
 
171
                   else
 
172
                   {
 
173
                        printf("Enter the diameter of the reflector (in %s) ", type);
 
174
                        scanf("%lf", &p[i][DIAMETER]);
 
175
                   }
 
176
                }
 
177
                else /* a director */
 
178
                {
 
179
                   printf("\n\nEnter location of director %d in %s (wrt. reflector at x=0.0) ", i-1, type);
 
180
                   scanf("%lf", &p[i][X]);
 
181
                   if( boom != TRUE)
 
182
                   {
 
183
                        printf("Enter the y position of director %d (in %s) ", i-1, type);
 
184
                        scanf("%lf", &p[i][Y]);
 
185
                   }
 
186
                   else
 
187
                        p[i][Y]=0.0;
 
188
                   printf("Enter the length of director %d (in %s) ", i-1,type);
 
189
                   scanf("%lf", &p[i][LENGTH]);
 
190
                   if(fixed_diameter == TRUE)
 
191
                        p[i][DIAMETER]=diameter;
 
192
                   else
 
193
                   {
 
194
                        printf("Enter the diameter of director %d (in %s) ", i-1, type);
 
195
                        scanf("%lf", &p[i][DIAMETER]);
 
196
                   }
 
197
                }
 
198
        }
 
199
        /* Now write data to disk */
 
200
        fp=fopen(filename,"wt");
 
201
        write_input_data_to_disk(fp, notes, frequency, min_f, max_f, step_f, elements   , driven, parasitic, angular_step, d, p, scale_factor); 
 
202
        fclose(fp);
 
203
        free_string(filename,0L, 1000L);
 
204
        free_string(notes,0L, 1000L);
 
205
        free_string(type,0L, 1000L);
 
206
        free_dmatrix(d, 1L, (long) driven, 1L, 6L);
 
207
        free_dmatrix(p, 1L, (long) parasitic , 1L, 4L);
 
208
        exit(0);
 
209
}
 
210