8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
< |
|
11 |
> |
#include <string.h> |
12 |
|
#include <stdlib.h> |
13 |
– |
|
13 |
|
#include <ctype.h> |
15 |
– |
|
14 |
|
#include <signal.h> |
15 |
+ |
#include <math.h> |
16 |
+ |
#include <unistd.h> /* XXX pipe() fork() etc, use common/process.c instead */ |
17 |
|
|
18 |
|
#include "random.h" |
19 |
|
|
33 |
|
|
34 |
|
ANGLE alpha[181] = {90, AEND}; |
35 |
|
ANGLE beta[181] = {30, 60, 90, 120, 150, AEND}; |
36 |
< |
ANGLE gamma[181] = {45, AEND}; |
36 |
> |
ANGLE sgamma[181] = {45, AEND}; /* gamma() is a function from gnu <math.h> */ |
37 |
|
|
38 |
|
char *target; /* target file name */ |
39 |
|
double targetw = 3.0; /* target width (inches) */ |
41 |
|
int xres = 16; /* x sample resolution */ |
42 |
|
int yres = 16; /* y sample resolution */ |
43 |
|
|
44 |
+ |
static void quit(int code); |
45 |
+ |
static void setscan(ANGLE *ang, char *arg); |
46 |
+ |
static void doscan(void); |
47 |
+ |
static void scanend(FILE *fp); |
48 |
+ |
static void makesource(ANGLE g); |
49 |
+ |
static void sendsamples(FILE *fp); |
50 |
+ |
static void writesample(FILE *fp, ANGLE a, ANGLE b); |
51 |
+ |
static FILE * scanstart(ANGLE g); |
52 |
+ |
static double readsample(FILE *fp); |
53 |
|
|
54 |
< |
main(argc, argv) |
55 |
< |
int argc; |
56 |
< |
char *argv[]; |
54 |
> |
int |
55 |
> |
main( |
56 |
> |
int argc, |
57 |
> |
char *argv[] |
58 |
> |
) |
59 |
|
{ |
49 |
– |
char *strcat(), *mktemp(); |
50 |
– |
int quit(); |
60 |
|
int i; |
61 |
|
|
62 |
+ |
#ifdef SIGHUP |
63 |
|
signal(SIGHUP, quit); |
64 |
+ |
#endif |
65 |
|
signal(SIGINT, quit); |
66 |
|
signal(SIGTERM, quit); |
67 |
+ |
#ifdef SIGXCPU |
68 |
|
signal(SIGXCPU, SIG_IGN); |
69 |
|
signal(SIGXFSZ, SIG_IGN); |
70 |
+ |
#endif |
71 |
|
|
72 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
73 |
|
switch (argv[i][1]) { |
108 |
|
break; |
109 |
|
case 'g': |
110 |
|
if (!strcmp(argv[i], "-gamma")) |
111 |
< |
setscan(gamma, argv[++i]); |
111 |
> |
setscan(sgamma, argv[++i]); |
112 |
|
else |
113 |
|
goto badopt; |
114 |
|
break; |
158 |
|
doscan(); |
159 |
|
|
160 |
|
quit(0); |
161 |
+ |
return 0; /* pro forma return */ |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
void |
166 |
< |
quit(code) /* unlink temp files and exit */ |
167 |
< |
int code; |
166 |
> |
quit( /* unlink temp files and exit */ |
167 |
> |
int code |
168 |
> |
) |
169 |
|
{ |
155 |
– |
int i; |
156 |
– |
|
170 |
|
unlink(sourcetemp); |
171 |
|
unlink(octreetemp); |
172 |
|
exit(code); |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
< |
setscan(ang, arg) /* set up scan according to arg */ |
177 |
< |
register ANGLE *ang; |
178 |
< |
register char *arg; |
176 |
> |
static void |
177 |
> |
setscan( /* set up scan according to arg */ |
178 |
> |
register ANGLE *ang, |
179 |
> |
register char *arg |
180 |
> |
) |
181 |
|
{ |
182 |
|
int start = 0, finish = -1, step = 1; |
183 |
|
|
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
< |
doscan() /* do scan for target */ |
229 |
> |
static void |
230 |
> |
doscan(void) /* do scan for target */ |
231 |
|
{ |
216 |
– |
FILE *fopen(), *scanstart(); |
217 |
– |
double readsample(); |
232 |
|
FILE *fp; |
233 |
|
ANGLE *a, *b, *g; |
234 |
|
|
235 |
|
printf("Alpha\tBeta\tGamma\tDistribution for \"%s\"\n", target); |
236 |
< |
for (g = gamma; *g != AEND; g++) { |
236 |
> |
for (g = sgamma; *g != AEND; g++) { |
237 |
|
fp = scanstart(*g); |
238 |
|
for (b = beta; *b != AEND; b++) /* read data */ |
239 |
|
for (a = alpha; *a != AEND; a++) |
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
< |
FILE * |
248 |
< |
scanstart(g) /* open scanner pipeline */ |
249 |
< |
ANGLE g; |
247 |
> |
static FILE * |
248 |
> |
scanstart( /* open scanner pipeline */ |
249 |
> |
ANGLE g |
250 |
> |
) |
251 |
|
{ |
237 |
– |
char *fgets(); |
252 |
|
int p1[2], p2[2]; |
253 |
|
int pid; |
254 |
|
FILE *fp; |
298 |
|
err: |
299 |
|
fprintf(stderr, "System error in scanstart\n"); |
300 |
|
quit(1); |
301 |
+ |
return NULL; /* pro forma return */ |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
< |
scanend(fp) /* done with scanner input */ |
306 |
< |
FILE *fp; |
305 |
> |
static void |
306 |
> |
scanend( /* done with scanner input */ |
307 |
> |
FILE *fp |
308 |
> |
) |
309 |
|
{ |
310 |
|
fclose(fp); |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
< |
makesource(g) /* make a source (output normalized) */ |
315 |
< |
ANGLE g; |
314 |
> |
static void |
315 |
> |
makesource( /* make a source (output normalized) */ |
316 |
> |
ANGLE g |
317 |
> |
) |
318 |
|
{ |
319 |
< |
FILE *fp, *fopen(); |
320 |
< |
double srcdir[3], sin(), cos(); |
319 |
> |
FILE *fp; |
320 |
> |
double srcdir[3]; |
321 |
|
|
322 |
|
srcdir[0] = sin(atorad(g)); |
323 |
|
srcdir[1] = 0.0; |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
< |
sendsamples(fp) /* send our samples to fp */ |
339 |
< |
FILE *fp; |
338 |
> |
static void |
339 |
> |
sendsamples( /* send our samples to fp */ |
340 |
> |
FILE *fp |
341 |
> |
) |
342 |
|
{ |
343 |
|
ANGLE *a, *b; |
344 |
|
|
348 |
|
} |
349 |
|
|
350 |
|
|
351 |
< |
writesample(fp, a, b) /* write out sample ray grid */ |
352 |
< |
FILE *fp; |
353 |
< |
ANGLE a, b; |
351 |
> |
static void |
352 |
> |
writesample( /* write out sample ray grid */ |
353 |
> |
FILE *fp, |
354 |
> |
ANGLE a, |
355 |
> |
ANGLE b |
356 |
> |
) |
357 |
|
{ |
334 |
– |
double sin(), cos(); |
358 |
|
float sp[6]; |
359 |
|
int i, j; |
360 |
|
|
378 |
|
} |
379 |
|
|
380 |
|
|
381 |
< |
double |
382 |
< |
readsample(fp) /* read in sample ray grid */ |
383 |
< |
FILE *fp; |
381 |
> |
static double |
382 |
> |
readsample( /* read in sample ray grid */ |
383 |
> |
FILE *fp |
384 |
> |
) |
385 |
|
{ |
386 |
|
double sum; |
387 |
|
float col[3]; |