12 |
|
*/ |
13 |
|
|
14 |
|
#include <stdlib.h> |
15 |
– |
#include <stdio.h> |
16 |
– |
#include <string.h> |
15 |
|
#include <math.h> |
16 |
|
|
17 |
+ |
#include "rtio.h" |
18 |
+ |
#include "rterror.h" |
19 |
+ |
#include "resolu.h" |
20 |
+ |
#include "calcomp.h" |
21 |
+ |
|
22 |
|
#define ZNAME "Z`SYS`" /* z function name */ |
23 |
|
#define RNAME "R`SYS`" /* r function name */ |
24 |
|
|
31 |
|
#define UP 04 |
32 |
|
#define DOWN 010 |
33 |
|
|
31 |
– |
double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); |
34 |
|
|
35 |
< |
void quit(), eputs(), wputs(); |
34 |
< |
|
35 |
< |
|
35 |
> |
void |
36 |
|
computen(nzp, nrp, z0, r0, z1, r1) /* compute normal */ |
37 |
|
double *nzp, *nrp, z0, r0, z1, r1; |
38 |
|
{ |
46 |
|
} |
47 |
|
|
48 |
|
|
49 |
– |
void |
50 |
– |
eputs(msg) |
51 |
– |
char *msg; |
52 |
– |
{ |
53 |
– |
fputs(msg, stderr); |
54 |
– |
} |
55 |
– |
|
56 |
– |
|
57 |
– |
void |
58 |
– |
wputs(msg) |
59 |
– |
char *msg; |
60 |
– |
{ |
61 |
– |
eputs(msg); |
62 |
– |
} |
63 |
– |
|
64 |
– |
|
65 |
– |
void |
66 |
– |
quit(code) |
67 |
– |
int code; |
68 |
– |
{ |
69 |
– |
exit(code); |
70 |
– |
} |
71 |
– |
|
72 |
– |
|
73 |
– |
printhead(ac, av) /* print command header */ |
74 |
– |
register int ac; |
75 |
– |
register char **av; |
76 |
– |
{ |
77 |
– |
putchar('#'); |
78 |
– |
while (ac--) { |
79 |
– |
putchar(' '); |
80 |
– |
fputs(*av++, stdout); |
81 |
– |
} |
82 |
– |
putchar('\n'); |
83 |
– |
} |
84 |
– |
|
85 |
– |
|
49 |
|
double |
50 |
< |
l_hermite() |
50 |
> |
l_hermite(char *nm) |
51 |
|
{ |
52 |
|
double t; |
53 |
|
|
60 |
|
|
61 |
|
|
62 |
|
double |
63 |
< |
l_bezier() |
63 |
> |
l_bezier(char *nm) |
64 |
|
{ |
65 |
|
double t; |
66 |
|
|
73 |
|
|
74 |
|
|
75 |
|
double |
76 |
< |
l_bspline() |
76 |
> |
l_bspline(char *nm) |
77 |
|
{ |
78 |
|
double t; |
79 |
|
|
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
+ |
int |
89 |
|
main(argc, argv) |
90 |
|
int argc; |
91 |
|
char *argv[]; |
92 |
|
{ |
129 |
– |
extern long eclock; |
93 |
|
char stmp[256]; |
94 |
|
char *modname; |
95 |
|
int smooth = 0; |
98 |
|
int i, nseg; |
99 |
|
int orient; |
100 |
|
|
101 |
+ |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
102 |
+ |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
103 |
|
varset("PI", ':', PI); |
104 |
|
funset("hermite", 5, ':', l_hermite); |
105 |
|
funset("bezier", 5, ':', l_bezier); |
111 |
|
for (i = 6; i < argc; i++) |
112 |
|
if (!strcmp(argv[i], "-e")) |
113 |
|
scompile(argv[++i], NULL, 0); |
114 |
< |
else if (!strcmp(argv[i], "-f")) |
115 |
< |
fcompile(argv[++i]); |
116 |
< |
else if (!strcmp(argv[i], "-s")) |
114 |
> |
else if (!strcmp(argv[i], "-f")) { |
115 |
> |
char *fpath = getpath(argv[++i], getrlibpath(), 0); |
116 |
> |
if (fpath == NULL) { |
117 |
> |
fprintf(stderr, "%s: cannot find file '%s'\n", |
118 |
> |
argv[0], argv[i]); |
119 |
> |
quit(1); |
120 |
> |
} |
121 |
> |
fcompile(fpath); |
122 |
> |
} else if (!strcmp(argv[i], "-s")) |
123 |
|
smooth = 1; |
124 |
|
else |
125 |
|
goto userror; |
128 |
|
scompile(stmp, NULL, 0); |
129 |
|
sprintf(stmp, "%s(t)=%s;", RNAME, argv[4]); |
130 |
|
scompile(stmp, NULL, 0); |
131 |
< |
nseg = atoi(argv[5]); |
131 |
> |
nseg = eval(argv[5]) + .5; |
132 |
|
if (nseg <= 0) |
133 |
|
goto userror; |
134 |
|
modname = smooth ? "Phong" : argv[1]; |
135 |
|
|
136 |
< |
printhead(argc, argv); |
137 |
< |
eclock = 0; |
136 |
> |
fputs("# ", stdout); |
137 |
> |
printargs(argc, argv, stdout); |
138 |
> |
doptimize(1); |
139 |
> |
eclock++; |
140 |
|
|
141 |
|
lastnz = lastnr = 0.0; |
142 |
|
t = 0.0; |
171 |
|
printf("0\n4\n"); |
172 |
|
if (orient&(UP|DOWN)) { |
173 |
|
t = (nextnz - lastnz)/(z - lastz); |
174 |
< |
printf("\t%15.9g\t%15.9g\n", |
174 |
> |
printf("\t%18.12g\t%18.12g\n", |
175 |
|
t, lastnz - t*lastz); |
176 |
|
} else |
177 |
|
printf("\t0\t%d\n", orient&IN ? 1 : -1); |
178 |
|
if (orient&(OUT|IN)) { |
179 |
|
t = (nextnr - lastnr)/(r - lastr); |
180 |
< |
printf("\t%15.9g\t%15.9g\n", |
180 |
> |
printf("\t%18.12g\t%18.12g\n", |
181 |
|
t, lastnr - t*lastr); |
182 |
|
} else |
183 |
|
printf("\t0\t%d\n", orient&UP ? 1 : -1); |
187 |
|
orient&DOWN ? "tube" : "cylinder", |
188 |
|
argv[2], i); |
189 |
|
printf("0\n0\n7\n"); |
190 |
< |
printf("\t0\t0\t%15.9g\n", lastz); |
191 |
< |
printf("\t0\t0\t%15.9g\n", z); |
192 |
< |
printf("\t%15.9g\n", r); |
190 |
> |
printf("\t0\t0\t%18.12g\n", lastz); |
191 |
> |
printf("\t0\t0\t%18.12g\n", z); |
192 |
> |
printf("\t%18.12g\n", r); |
193 |
|
} else if (!(orient&(UP|DOWN))) { |
194 |
|
printf("\n%s ring %s.%d\n", modname, argv[2], i); |
195 |
|
printf("0\n0\n8\n"); |
196 |
< |
printf("\t0\t0\t%15.9g\n", z); |
197 |
< |
printf("\t0\t0\t%15.9g\n", orient&IN ? 1.0 : -1.0); |
198 |
< |
printf("\t%15.9g\t%15.9g\n", lastr, r); |
196 |
> |
printf("\t0\t0\t%18.12g\n", z); |
197 |
> |
printf("\t0\t0\t%18.12g\n", orient&IN ? 1.0 : -1.0); |
198 |
> |
printf("\t%18.12g\t%18.12g\n", lastr, r); |
199 |
|
} else { |
200 |
|
printf("\n%s %s %s.%d\n", modname, |
201 |
|
orient&DOWN ? "cup" : "cone", |
202 |
|
argv[2], i); |
203 |
|
printf("0\n0\n8\n"); |
204 |
< |
printf("\t0\t0\t%15.9g\n", lastz); |
205 |
< |
printf("\t0\t0\t%15.9g\n", z); |
206 |
< |
printf("\t%15.9g\t%15.9g\n", lastr, r); |
204 |
> |
printf("\t0\t0\t%18.12g\n", lastz); |
205 |
> |
printf("\t0\t0\t%18.12g\n", z); |
206 |
> |
printf("\t%18.12g\t%18.12g\n", lastr, r); |
207 |
|
} |
208 |
|
endfor: |
209 |
|
lastz = z; lastr = r; |
211 |
|
lastnz = nz; lastnr = nr; |
212 |
|
nz = nextnz; nr = nextnr; |
213 |
|
} |
214 |
< |
quit(0); |
214 |
> |
return 0; |
215 |
|
|
216 |
|
userror: |
217 |
|
fprintf(stderr, |
218 |
|
"Usage: %s material name z(t) r(t) nseg [-e expr] [-f file] [-s]\n", |
219 |
|
argv[0]); |
220 |
< |
quit(1); |
220 |
> |
return 1; |
221 |
|
} |
222 |
|
|
223 |
|
|