source: buchla-68k/orig/BUCHLA/DBWAVE.C@ 0170798

Last change on this file since 0170798 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 5.9 KB
RevLine 
[3ae31e9]1/*
2 =============================================================================
3 dbwave.c -- Harmonic table file generator for MIDAS-VII
4 Written by: D.N. Lynx Crowe
5
6 See VERSION, below, for version number and date.
7
8 This program creates a .h file to be included as harmonic
9 coefficient tables for MIDAS-VII.
10
11 WIDTH is the number of points in the table
12 CENTER is the center point in the table
13 N is the number of points scanned on either side of CENTER
14 K and L are the lower and upper limits of the scan, respectively
15 PER is the number of values generated per line
16
17 HARM is the number of harmonics generated
18 i is the harmonic number (1 is the fundamental)
19 j is the point number, K LE j LE L
20 =============================================================================
21*/
22
23#include "stdio.h"
24#include "math.h"
25#include "stddefs.h"
26
27#define PGMNAME "dbwave"
28#define VERSION "Version 16 -- 1988-09-08"
29
30#define FILENAME "knmtab.h" /* output file name */
31#define TABNAME "knmtab" /* table name */
32
33#define WIDTH 256 /* table width */
34#define RANGE 1023 /* maximum value */
35#define HARM 32 /* number of harmonics */
36
37#define N 127 /* number of points scanned */
38#define PER 16 /* values per line */
39
40#define CENTER (WIDTH / 2) /* center of the table */
41#define K (CENTER - N) /* first point scanned */
42#define L (CENTER + N) /* last point scanned */
43
44#define M_PI 3.14159265358979323846
45#define M_HALFPI (M_PI / 2.0)
46
47#define ACOSFN(x) atan(sqrt(1.0 - (x * x)) / x)
48
49extern char *now(); /* get current date-time group */
50extern char *strcat(); /* append a string onto another */
51extern char *strcpy(); /* copy a string into another */
52
53/*
54
55*/
56
57/* variables */
58
59double a; /* unscaled harmonic coefficient */
60double c; /* scaled harmonic coefficient */
61double y; /* intermediate coefficient value */
62
63int nol; /* number of values on the line so far */
64
65FILE *fp; /* output file pointer */
66
67char bar[81]; /* bar of equal signs */
68char dtg[32]; /* date-time group */
69char intc[32]; /* value output work area */
70char result[128]; /* line output work area */
71
72/*
73
74*/
75
76/*
77 =============================================================================
78 CalcArc() -- Calculate the scaled Arc Cosine of 'arg'
79 =============================================================================
80*/
81
82double
83CalcArc(arg)
84double arg;
85{
86 double y;
87
88 if (arg EQ 0.0) /* Return PI/2 if arg = 0.0 */
89 return((double)M_HALFPI);
90
91 y = ACOSFN(arg);
92
93 if (arg < 0.0) /* Adjust by PI if arg was negative */
94 y = y + (double)M_PI;
95
96 return(y);
97}
98
99/*
100 =============================================================================
101 DoOut() -- Output result string
102 =============================================================================
103*/
104
105DoOut(j, k)
106int j, k;
107{
108 if (j EQ (WIDTH - 1)) { /* end of line ? */
109
110 if (k EQ HARM) /* last table ? */
111 fprintf(fp, "\t%s }\t/* %3d */\n", result, j);
112 else
113 fprintf(fp, "\t%s },\t/* %3d */\n", result, j);
114
115 } else {
116
117 fprintf(fp, "\t%s,\t/* %3d */\n", result, j);
118 }
119
120 result[0] = '\0';
121 nol = 0;
122}
123
124/*
125
126*/
127
128main()
129{
130 register int c, i, j;
131
132 printf("\n%s -- %s -- run on ",
133 PGMNAME, VERSION);
134
135 now(dtg);
136
137 printf("%10.10s at %s\n\n",
138 dtg, &dtg[12]);
139
140 for (c = 0; c < 3; c++)
141 bar[c] = ' ';
142
143 for (; c < 80; c++)
144 bar[c] = '=';
145
146 bar[80] = '\0';
147
148 printf("Generating coefficient tables for %d harmonics\n\n", HARM);
149
150 printf("Full scale range = %d\n", RANGE);
151 printf("Width of table = %d\n", WIDTH);
152 printf("Center of table = %d\n", CENTER);
153 printf("Scan width (N) = %d\n", N);
154 printf("Points scanned = %d thru %d\n\n", K, L);
155
156 printf("Creating file \"%s\"\n", FILENAME);
157
158 if ((FILE *)NULL EQ (fp = fopen(FILENAME, "w"))) {
159
160 printf("ERROR: unable to open \"%s\" for writing\n", FILENAME);
161 exit(1);
162 }
163
164 printf("\n");
165
166 fprintf(fp, "/*\n%s\n\t %s -- MIDAS-VII Harmonic coefficient tables\n",
167 bar, FILENAME);
168
169 fprintf(fp, "\tCalculated %10.10s -- %s\n%s\n*/\n\n",
170 dtg, &dtg[12], bar);
171
172 fprintf(fp, "/*\n%s\n", bar);
173 fprintf(fp, "\tCalculated by dbwave.c -- %s\n", VERSION);
174 fprintf(fp, "\tfor MIDAS-VII using:\n");
175 fprintf(fp, "\n");
176 fprintf(fp, "\t\tFull scale range = %d\n", RANGE);
177 fprintf(fp, "\n");
178 fprintf(fp, "\t\tWidth of table = %d\n", WIDTH);
179 fprintf(fp, "\t\tCenter of table = %d\n", CENTER);
180 fprintf(fp, "\t\tScan width (N) = %d\n", N);
181 fprintf(fp, "\t\tPoints scanned = %d thru %d\n", K, L);
182 fprintf(fp, "%s\n*/\n\n", bar);
183
184 fprintf(fp, "short\t%s[%d][%d] = {\n", TABNAME, HARM, WIDTH);
185 fprintf(fp, "\n");
186
187/*
188
189*/
190 for (i = 1; i < (HARM + 1); i++) {
191
192 printf("Calculating harmonic %d ...\r", i);
193
194 if (i & 1) {
195
196 fprintf(fp, "/* \f\n");
197 fprintf(fp, "*/\n");
198 }
199
200 fprintf(fp, "\n");
201 fprintf(fp, "/* Harmonic table # %d */\n", i);
202 fprintf(fp, "\n");
203
204 nol = 1;
205 result[0] = '\0';
206
207 for (j = 0; j < K; j++) {
208
209 if (nol EQ 1) {
210
211 if (j EQ 0)
212 strcat(result, "{ 0");
213 else
214 strcat(result, " 0");
215
216 } else {
217
218 strcat(result, ", 0");
219 }
220
221 if (nol EQ PER)
222 DoOut(j, i);
223
224 ++nol;
225 }
226/*
227
228*/
229 for (; j < (L + 1); j++) {
230
231 y = CalcArc((double)(j - CENTER) / (double)N);
232 a = cos((double)i * y);
233 c = ((double)RANGE * a) + 0.5;
234
235 sprintf(intc, "%5d", (int)c);
236
237 if (nol EQ 1)
238 strcat(strcat(result, " "), intc);
239 else
240 strcat(strcat(result, ","), intc);
241
242 if (nol EQ PER)
243 DoOut(j, i);
244
245 ++nol;
246 }
247
248 for (; j < WIDTH; j++) {
249
250 if (nol EQ 1)
251 strcat(result, " 0");
252 else
253 strcat(result, ", 0");
254
255 if (nol EQ PER)
256 DoOut(j, i);
257
258 ++nol;
259 }
260
261 if (nol NE 1)
262 DoOut(j - 1, i);
263 }
264
265 fprintf(fp, "};\n");
266 fclose(fp);
267
268 printf("Output complete. End of program.\n");
269 exit(0);
270}
Note: See TracBrowser for help on using the repository browser.