9 |
|
|
10 |
|
#include <ctype.h> |
11 |
|
#include <string.h> |
12 |
+ |
#include <math.h> |
13 |
|
|
14 |
|
#include "tgraph.h" |
15 |
+ |
#include "plot.h" |
16 |
|
|
15 |
– |
|
17 |
|
#define isfloat(a) (isdigit(a) || (a) == '-' || (a) == '.' || \ |
18 |
|
(a) == 'E' || (a) == '+' || (a) == 'e') |
19 |
|
|
20 |
|
|
20 |
– |
extern double log10(); |
21 |
|
|
22 |
< |
|
23 |
< |
|
24 |
< |
|
25 |
< |
|
26 |
< |
initialize() |
27 |
< |
|
22 |
> |
extern void |
23 |
> |
initialize(void) |
24 |
|
{ |
25 |
|
int i; |
26 |
|
|
27 |
|
for (i = 0; i < NCUR; i++) |
28 |
|
usecurve[i] = 1; |
29 |
+ |
} |
30 |
|
|
34 |
– |
} |
31 |
|
|
32 |
< |
|
33 |
< |
|
34 |
< |
|
35 |
< |
|
40 |
< |
|
41 |
< |
option(s) /* record option */ |
42 |
< |
|
43 |
< |
char *s; |
44 |
< |
|
32 |
> |
extern void |
33 |
> |
option( /* record option */ |
34 |
> |
char *s |
35 |
> |
) |
36 |
|
{ |
37 |
|
double atof(); |
38 |
|
char *sp; |
39 |
|
short userror = 0; |
40 |
|
int i; |
41 |
|
|
42 |
< |
if (s[0] == '-') |
42 |
> |
if (s[0] == '-') { |
43 |
|
|
44 |
|
switch(s[1]) { |
45 |
|
|
83 |
|
userror = *sp; |
84 |
|
break; |
85 |
|
} |
86 |
< |
else |
86 |
> |
} else { |
87 |
|
|
88 |
|
switch (s[1]) { |
89 |
|
|
102 |
|
usecurve[*sp-'@'] = 1; |
103 |
|
userror = *sp; |
104 |
|
} |
105 |
+ |
} |
106 |
|
|
107 |
|
if (userror) |
108 |
|
error(USER, "options are [-sSYMRAD][-g][-lx][-ly][-p{dr}][-xXMIN][+xXMAX][-yYMIN][+yYMAX][-C..|+C..]"); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
< |
|
114 |
< |
|
115 |
< |
normalize(fp, fout) /* get extrema from file */ |
116 |
< |
|
117 |
< |
FILE *fp, *fout; |
126 |
< |
|
113 |
> |
extern void |
114 |
> |
normalize( /* get extrema from file */ |
115 |
> |
FILE *fp, |
116 |
> |
FILE *fout |
117 |
> |
) |
118 |
|
{ |
119 |
|
char line[255]; |
120 |
|
double x, y; |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
< |
|
164 |
< |
|
165 |
< |
makeaxis(flag) /* make and print x and y axis */ |
166 |
< |
|
176 |
< |
int flag; |
177 |
< |
|
163 |
> |
extern void |
164 |
> |
makeaxis( /* make and print x and y axis */ |
165 |
> |
int flag |
166 |
> |
) |
167 |
|
{ |
168 |
|
double xstep, ystep, step(), pos; |
169 |
|
int xorg, yorg; |
170 |
|
char *format, stemp[32]; |
171 |
|
|
172 |
|
/* set limits */ |
173 |
< |
if (polar) |
173 |
> |
if (polar) { |
174 |
|
if (xmax-xmin < ymax-ymin) /* null aspect for polar */ |
175 |
|
xmax = xmin + ymax-ymin; |
176 |
|
else |
177 |
|
ymax = ymin + xmax-xmin; |
178 |
< |
else { |
179 |
< |
if (xmnset > -FHUGE) |
178 |
> |
} else { |
179 |
> |
if (xmnset > -FHUGE) { |
180 |
|
if (logx) { |
181 |
|
if (xmnset > FTINY) |
182 |
|
xmin = log10(xmnset); |
183 |
< |
} |
195 |
< |
else |
183 |
> |
} else |
184 |
|
xmin = xmnset; |
185 |
< |
if (xmxset < FHUGE) |
185 |
> |
} |
186 |
> |
if (xmxset < FHUGE) { |
187 |
|
if (logx) { |
188 |
|
if (xmxset > FTINY) |
189 |
|
xmax = log10(xmxset); |
190 |
< |
} |
202 |
< |
else |
190 |
> |
} else |
191 |
|
xmax = xmxset; |
192 |
< |
if (ymnset > -FHUGE) |
192 |
> |
} |
193 |
> |
if (ymnset > -FHUGE) { |
194 |
|
if (logy) { |
195 |
|
if (ymnset > FTINY) |
196 |
|
ymin = log10(ymnset); |
197 |
< |
} |
209 |
< |
else |
197 |
> |
} else |
198 |
|
ymin = ymnset; |
199 |
< |
if (ymxset < FHUGE) |
199 |
> |
} |
200 |
> |
if (ymxset < FHUGE) { |
201 |
|
if (logy) { |
202 |
|
if (ymxset > FTINY) |
203 |
|
ymax = log10(ymxset); |
204 |
< |
} |
216 |
< |
else |
204 |
> |
} else |
205 |
|
ymax = ymxset; |
206 |
+ |
} |
207 |
|
} |
208 |
|
/* set step */ |
209 |
|
if (logx) { |
223 |
|
xsize = xmax - xmin; |
224 |
|
ysize = ymax - ymin; |
225 |
|
|
226 |
< |
if (polar) /* null aspect again */ |
226 |
> |
if (polar) { /* null aspect again */ |
227 |
|
if (xsize < ysize) |
228 |
|
xmax = xmin + (xsize = ysize); |
229 |
|
else |
230 |
|
ymax = ymin + (ysize = xsize); |
231 |
+ |
} |
232 |
|
|
233 |
|
if (xmin > 0.0) |
234 |
|
xorg = XBEG; |
250 |
|
if (flag & ORIGIN) |
251 |
|
plseg(010, XBEG, yorg, XBEG+XSIZ-1, yorg); |
252 |
|
|
263 |
– |
#if CPM || MAC |
264 |
– |
if (xstep > 1.0) |
265 |
– |
format = "%5.0f"; |
266 |
– |
else |
267 |
– |
format = "%5.3f"; |
268 |
– |
#else |
253 |
|
format = "%5g"; |
270 |
– |
#endif |
254 |
|
if (logx) |
255 |
|
format = "1e%-3.0f"; |
256 |
|
|
257 |
|
for (pos = xmin; pos < xmax+xstep/2; pos += xstep) { |
258 |
< |
if (flag & XTICS) |
258 |
> |
if (flag & XTICS) { |
259 |
|
if (polar) |
260 |
|
plseg(010, XCONV(pos), yorg-TSIZ/2, XCONV(pos), yorg+TSIZ/2); |
261 |
|
else { |
262 |
|
plseg(010, XCONV(pos), YBEG, XCONV(pos), YBEG-TSIZ); |
263 |
|
plseg(010, XCONV(pos), YBEG+YSIZ-1, XCONV(pos), YBEG+YSIZ-1+TSIZ); |
264 |
|
} |
265 |
+ |
} |
266 |
|
if (flag & XNUMS) { |
267 |
|
sprintf(stemp, format, pos); |
268 |
|
if (polar) |
283 |
|
if (flag & ORIGIN) |
284 |
|
plseg(010, xorg, YBEG, xorg, YBEG+YSIZ-1); |
285 |
|
|
302 |
– |
#if CPM || MAC |
303 |
– |
if (ystep > 1.0) |
304 |
– |
format = "%5.0f"; |
305 |
– |
else |
306 |
– |
format = "%5.3f"; |
307 |
– |
#else |
286 |
|
format = "%5g"; |
309 |
– |
#endif |
287 |
|
if (logy) |
288 |
|
format = "1e%-3.0f"; |
289 |
|
|
290 |
|
for (pos = ymin; pos < ymax+ystep/2; pos += ystep) { |
291 |
< |
if (flag & YTICS) |
291 |
> |
if (flag & YTICS) { |
292 |
|
if (polar) |
293 |
|
plseg(010, xorg-TSIZ/2, YCONV(pos), xorg+TSIZ/2, YCONV(pos)); |
294 |
|
else { |
295 |
|
plseg(010, XBEG, YCONV(pos), XBEG-TSIZ, YCONV(pos)); |
296 |
|
plseg(010, XBEG+XSIZ-1, YCONV(pos), XBEG+XSIZ-1+TSIZ, YCONV(pos)); |
297 |
|
} |
298 |
+ |
} |
299 |
|
if (flag & YNUMS) { |
300 |
|
sprintf(stemp, format, pos); |
301 |
|
if (polar) |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
< |
|
316 |
< |
isdata(s) |
317 |
< |
|
318 |
< |
register char *s; |
341 |
< |
|
315 |
> |
extern int |
316 |
> |
isdata( |
317 |
> |
register char *s |
318 |
> |
) |
319 |
|
{ |
320 |
|
int commas = 0; |
321 |
|
|
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
< |
|
337 |
< |
|
338 |
< |
islabel(s) |
339 |
< |
|
363 |
< |
char s[]; |
364 |
< |
|
336 |
> |
extern int |
337 |
> |
islabel( |
338 |
> |
char *s |
339 |
> |
) |
340 |
|
{ |
341 |
|
int i; |
342 |
|
|
343 |
|
i = strlen(s) - 2; |
344 |
|
|
345 |
|
return(i > 0 && s[0] == '"' && s[i] == '"'); |
346 |
< |
} |
346 |
> |
} |
347 |
|
|
348 |
|
|
374 |
– |
|
375 |
– |
|
349 |
|
double |
350 |
< |
step(mn, mx) /* compute step size for axis */ |
351 |
< |
|
352 |
< |
double *mn, *mx; |
353 |
< |
|
350 |
> |
step( /* compute step size for axis */ |
351 |
> |
double *mn, |
352 |
> |
double *mx |
353 |
> |
) |
354 |
|
{ |
355 |
|
static int steps[] = {100, 50, 20, 10, 5, 2, 1}; |
356 |
|
int i; |
377 |
|
|
378 |
|
|
379 |
|
double |
380 |
< |
pown(x, n) /* raise x to an integer power */ |
381 |
< |
|
382 |
< |
double x; |
383 |
< |
int n; |
411 |
< |
|
380 |
> |
pown( /* raise x to an integer power */ |
381 |
> |
double x, |
382 |
> |
int n |
383 |
> |
) |
384 |
|
{ |
385 |
|
register int i; |
386 |
|
double p = 1.0; |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
< |
|
400 |
< |
|
401 |
< |
istitle(s) |
402 |
< |
|
431 |
< |
char *s; |
432 |
< |
|
399 |
> |
extern int |
400 |
> |
istitle( |
401 |
> |
char *s |
402 |
> |
) |
403 |
|
{ |
404 |
|
char word[32]; |
405 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
< |
|
415 |
< |
isdivlab(s) /* return TRUE if division label(s) */ |
416 |
< |
|
417 |
< |
register char *s; |
448 |
< |
|
414 |
> |
extern int |
415 |
> |
isdivlab( /* return TRUE if division label(s) */ |
416 |
> |
register char *s |
417 |
> |
) |
418 |
|
{ |
419 |
|
|
420 |
|
return(instr(s, "division") != NULL); |
422 |
|
|
423 |
|
|
424 |
|
|
425 |
< |
|
426 |
< |
isxlabel(s) |
427 |
< |
|
428 |
< |
register char *s; |
460 |
< |
|
425 |
> |
extern int |
426 |
> |
isxlabel( |
427 |
> |
register char *s |
428 |
> |
) |
429 |
|
{ |
430 |
|
register char *xindex = instr(s, "x "); |
431 |
|
|
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
< |
|
437 |
< |
|
438 |
< |
isylabel(s) |
439 |
< |
|
472 |
< |
register char *s; |
473 |
< |
|
436 |
> |
extern int |
437 |
> |
isylabel( |
438 |
> |
register char *s |
439 |
> |
) |
440 |
|
{ |
441 |
|
register char *yindex = instr(s, "y "); |
442 |
|
|
445 |
|
|
446 |
|
|
447 |
|
|
448 |
< |
char * |
449 |
< |
instr(s, t) /* return pointer to first occurrence of t in s */ |
450 |
< |
|
451 |
< |
char *s, |
452 |
< |
*t; |
487 |
< |
|
448 |
> |
extern char * |
449 |
> |
instr( /* return pointer to first occurrence of t in s */ |
450 |
> |
char *s, |
451 |
> |
char *t |
452 |
> |
) |
453 |
|
{ |
454 |
|
register char *pt, *ps; |
455 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
474 |
< |
|
475 |
< |
char * |
476 |
< |
snagquo(s) /* find and return quoted string within s */ |
477 |
< |
|
513 |
< |
register char *s; |
514 |
< |
|
474 |
> |
extern char * |
475 |
> |
snagquo( /* find and return quoted string within s */ |
476 |
> |
register char *s |
477 |
> |
) |
478 |
|
{ |
479 |
|
register char *rval = NULL; |
480 |
|
|
481 |
|
for ( ; *s; s++) |
482 |
< |
if (*s == '"') |
482 |
> |
if (*s == '"') { |
483 |
|
if (rval == NULL) |
484 |
|
rval = s+1; |
485 |
|
else { |
486 |
|
*s = '\0'; |
487 |
|
return(rval); |
488 |
|
} |
489 |
+ |
} |
490 |
|
|
491 |
|
return(NULL); |
492 |
|
} |
493 |
|
|
494 |
|
|
495 |
|
|
496 |
< |
|
497 |
< |
getdata(s, xp, yp) /* get data from line */ |
498 |
< |
|
499 |
< |
char *s; |
500 |
< |
double *xp, *yp; |
501 |
< |
|
496 |
> |
extern int |
497 |
> |
getdata( /* get data from line */ |
498 |
> |
char *s, |
499 |
> |
double *xp, |
500 |
> |
double *yp |
501 |
> |
) |
502 |
|
{ |
503 |
|
double sin(), cos(); |
504 |
|
int oobounds = 0; |
516 |
|
if (*yp < ymnset || *yp > ymxset) |
517 |
|
oobounds++; |
518 |
|
|
519 |
< |
if (logx) |
519 |
> |
if (logx) { |
520 |
|
if (*xp < FTINY) |
521 |
|
oobounds++; |
522 |
|
else |
523 |
|
*xp = log10(*xp); |
524 |
+ |
} |
525 |
|
|
526 |
< |
if (logy) |
526 |
> |
if (logy) { |
527 |
|
if (*yp < FTINY) |
528 |
|
oobounds++; |
529 |
|
else |
530 |
|
*yp = log10(*yp); |
531 |
+ |
} |
532 |
|
|
533 |
|
if (polar) { |
534 |
|
a = *xp; |
543 |
|
|
544 |
|
|
545 |
|
|
546 |
< |
|
547 |
< |
symout(a0, x, y, sname) /* output a symbol */ |
548 |
< |
|
549 |
< |
int a0; |
550 |
< |
int x, y; |
551 |
< |
char *sname; |
552 |
< |
|
546 |
> |
extern void |
547 |
> |
symout( /* output a symbol */ |
548 |
> |
int a0, |
549 |
> |
int x, |
550 |
> |
int y, |
551 |
> |
char *sname |
552 |
> |
) |
553 |
|
{ |
554 |
|
|
555 |
|
pprim(PSEG, a0, x-symrad, y-symrad, x+symrad, y+symrad, sname); |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
< |
|
561 |
< |
boxstring(a0, xmn, ymn, xmx, ymx, s) /* output a string within a box */ |
562 |
< |
|
563 |
< |
int a0; |
564 |
< |
int xmn, ymn, xmx, ymx; |
565 |
< |
char *s; |
566 |
< |
|
560 |
> |
extern void |
561 |
> |
boxstring( /* output a string within a box */ |
562 |
> |
int a0, |
563 |
> |
int xmn, |
564 |
> |
int ymn, |
565 |
> |
int xmx, |
566 |
> |
int ymx, |
567 |
> |
char *s |
568 |
> |
) |
569 |
|
{ |
570 |
|
int start; |
571 |
|
long size; |