ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/igraph.c
Revision: 1.5
Committed: Thu Feb 9 21:54:11 2023 UTC (15 months, 2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, HEAD
Changes since 1.4: +5 -7 lines
Log Message:
fix: compile error fixes related to redeclaration of eputs() and wputs()

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 1.5 static const char RCSid[] = "$Id: igraph.c,v 1.4 2003/11/15 02:13:37 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * igraph.c - interactive graphing program.
6     *
7     * 6/30/86
8     *
9     * Greg Ward Larson
10     */
11    
12     #include <stdio.h>
13     #include <ctype.h>
14     #include <setjmp.h>
15    
16 schorsch 1.2 #include "rtprocess.h"
17 schorsch 1.3 #include "rterror.h"
18 schorsch 1.4 #include "meta.h"
19     #include "mgraph.h"
20 greg 1.1 #include "mgvars.h"
21    
22     typedef struct {
23     char *descrip; /* description */
24     char *value; /* value */
25     } SMAP;
26    
27     #define NDEV 10 /* number of devices */
28    
29     SMAP dev[NDEV] = {
30     { "Tektronix 4014", "t4014" },
31     { "AED 512", "output aed5" },
32     { "X10 Window System", "xmeta" },
33     { "X11 Window System", "x11meta" },
34     { "Epson Printer", "output mx80" },
35     { "Mannesman-Tally Printer", "output mt160" },
36     { "Mannesman-Tally High Density", "output mt160l" },
37     { "Apple Imagewriter", "output imagew" },
38     { "Imagen Printer", "impress | ipr" },
39     { "Postscript Printer", "psmeta | lpr" },
40     };
41    
42     #define NTYP 7 /* number of plot types */
43    
44     SMAP typ[NTYP] = {
45     { "Cartesian Plot", "cartesian.plt" },
46     { "Polar Plot (degrees)", "polar.plt" },
47     { "Curve Plot (symbols & lines)", "curve.plt" },
48     { "Scatter Plot (symbols only)", "scatter.plt" },
49     { "Line Plot (lines only)", "line.plt" },
50     { "Function Plot (lines)", "function.plt" },
51     { "Box and Whisker Plot", "boxw.plt" },
52     };
53    
54     #define NCAL 3 /* number of calculation types */
55    
56     SMAP cal[NCAL] = {
57     { "Extrema, Average", "nma" },
58     { "Integral", "ni" },
59     { "Linear Regression", "nl" },
60     };
61    
62     char *progname;
63    
64     char *libpath[4];
65    
66     static int recover = 0; /* try to recover? */
67    
68     static jmp_buf env; /* setjmp buffer */
69    
70     static char curfile[64] = "temp.plt"; /* current file name */
71    
72 schorsch 1.3 static void mainmenu(void);
73     static void uwait(void);
74     static void gcompute(void);
75     static void setvars(int nvar, VARIABLE vars[]);
76     static void plotout(void);
77     static void settype(void);
78     static char *getfile(void);
79 greg 1.1
80 schorsch 1.3 int
81 greg 1.1 main(argc, argv)
82     int argc;
83     char *argv[];
84     {
85     char *getenv();
86     int i;
87    
88     progname = argv[0];
89     libpath[0] = "./";
90     if ((libpath[i=1] = getenv("MDIR")) != NULL)
91     i++;
92     libpath[i++] = MDIR;
93     libpath[i] = NULL;
94    
95     for (i = 1; i < argc; i++)
96     mgload(strcpy(curfile, argv[i]));
97    
98     mainmenu();
99    
100     quit(0);
101 schorsch 1.4 return 0; /* pro forma return */
102 greg 1.1 }
103    
104 greg 1.5 void
105     eputs(const char *msg) /* print error message */
106 greg 1.1 {
107     fputs(msg, stderr);
108     }
109    
110 greg 1.5 void
111     quit(int code) /* recover or quit */
112 greg 1.1 {
113     if (code && recover--)
114     longjmp(env, 1);
115     exit(code);
116     }
117    
118    
119 schorsch 1.3 static void
120     mainmenu(void) /* the main menu loop */
121 greg 1.1 {
122     char sbuf[128];
123    
124     for ( ; ; ) {
125     printf("\nGRAPH MENU\n");
126     printf("\t1 New Plot\n");
127     printf("\t2 Set Plot Type\n");
128     printf("\t3 Load Plot File\n");
129     printf("\t4 Save Plot File\n");
130     printf("\t5 Change Plot Variable\n");
131     printf("\t6 Change Curve Variable\n");
132     printf("\t7 Output Plot\n");
133     printf("\t8 Escape Command\n");
134     printf("\t9 Computation\n");
135     printf("\t10 Quit\n");
136    
137     printf("\nChoice: ");
138 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
139 greg 1.1 if (feof(stdin))
140     return;
141     switch (atoi(sbuf)) {
142     case 1: /* new plot */
143     mgclearall();
144     break;
145     case 2: /* set plot type */
146     settype();
147     break;
148     case 3: /* load plot file */
149     if (setjmp(env) == 0) {
150     recover = 1;
151     mgload(getfile());
152     recover = 0;
153     } else
154     uwait();
155     break;
156     case 4: /* save plot file */
157     if (setjmp(env) == 0) {
158     recover = 1;
159     mgsave(getfile());
160     recover = 0;
161     } else
162     uwait();
163     break;
164     case 5: /* set plot variable */
165     setvars(NVARS, gparam);
166     break;
167     case 6: /* set curve variable */
168     printf("\nCurve (A-%c): ", MAXCUR-1+'A');
169 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
170 greg 1.1 if (islower(sbuf[0]))
171     sbuf[0] -= 'a';
172     else if (isupper(sbuf[0]))
173     sbuf[0] -= 'A';
174     else
175     break;
176     if (sbuf[0] < MAXCUR)
177 schorsch 1.4 setvars(NCVARS, cparam[(int)sbuf[0]]);
178 greg 1.1 break;
179     case 7: /* output plot */
180     plotout();
181     break;
182     case 8: /* escape command */
183     printf("\nCommand: ");
184 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
185 greg 1.1 if (sbuf[0]) {
186     system(sbuf);
187     uwait();
188     }
189     break;
190     case 9: /* computation */
191     gcompute();
192     break;
193     case 10: /* quit */
194     return;
195     }
196     }
197     }
198    
199    
200 schorsch 1.3 static char *
201     getfile(void) /* get file name from user */
202 greg 1.1 {
203     char sbuf[128];
204    
205     printf("\nFile (%s): ", curfile);
206 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
207 greg 1.1 if (sbuf[0] == '-')
208     return(NULL);
209     if (sbuf[0])
210     strcpy(curfile, sbuf);
211     return(curfile);
212     }
213    
214 schorsch 1.3 static void
215     settype(void) /* set plot type */
216 greg 1.1 {
217     char sbuf[128];
218     int i;
219    
220     printf("\nPLOT TYPE\n");
221    
222     for (i = 0; i < NTYP; i++)
223     printf("\t%d %s\n", i+1, typ[i].descrip);
224    
225     printf("\nChoice (0): ");
226 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
227 greg 1.1 i = atoi(sbuf) - 1;
228     if (i < 0 || i >= NTYP)
229     return;
230     sprintf(sbuf, "include=%s", typ[i].value);
231     setmgvar("plot type", stdin, sbuf);
232     }
233    
234    
235 schorsch 1.3 static void
236     plotout(void) /* output our graph */
237 greg 1.1 {
238 schorsch 1.2 extern FILE *pout;
239 greg 1.1 char sbuf[128];
240 schorsch 1.4 char *command = NULL;
241 greg 1.1 int i;
242    
243     printf("\nOUTPUT PLOT\n");
244    
245     for (i = 0; i < NDEV; i++)
246     printf("\t%d %s\n", i+1, dev[i].descrip);
247     printf("\t%d Dumb Terminal\n", NDEV+1);
248     printf("\t%d Other\n", NDEV+2);
249    
250     printf("\nChoice (0): ");
251 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
252 greg 1.1 i = atoi(sbuf) - 1;
253     if (i < 0 || i > NDEV+1)
254     return;
255     if (i < NDEV)
256     command = dev[i].value;
257     else if (i == NDEV) {
258     if (setjmp(env) == 0) {
259     recover = 1;
260     cgraph(79, 22);
261     recover = 0;
262     }
263     uwait();
264     return;
265     } else if (i == NDEV+1) {
266     printf("\nDriver command: ");
267 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
268 greg 1.1 if (!sbuf[0])
269     return;
270     command = sbuf;
271     }
272     if ((pout = popen(command, "w")) == NULL) {
273     fprintf(stderr, "%s: cannot execute device driver: %s\n",
274     progname, dev[i].value);
275     quit(1);
276     }
277     if (setjmp(env) == 0) {
278     recover = 1;
279     mgraph();
280     recover = 0;
281     } else
282     uwait();
283     mdone();
284     pclose(pout);
285     }
286    
287    
288 schorsch 1.3 static void
289     setvars( /* set variables */
290     int nvar,
291     VARIABLE vars[])
292 greg 1.1 {
293     char sbuf[128];
294     int i, j;
295    
296     for ( ; ; ) {
297     printf("\nVARIABLES\n");
298    
299     for (i = 0; i < nvar; i++)
300     printf("\t%d %s\n", i+1, vars[i].descrip == NULL ?
301     vars[i].name : vars[i].descrip);
302    
303     printf("\nChoice (0): ");
304 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
305 greg 1.1 i = atoi(sbuf) - 1;
306     if (i < 0 || i >= nvar)
307     return;
308     printf("\n%s", vars[i].name);
309     if (vars[i].type == FUNCTION)
310     printf("(x)");
311     if (vars[i].flags & DEFINED) {
312     mgtoa(sbuf, &vars[i]);
313     printf(" (%s)", sbuf);
314     }
315     printf(": ");
316     if (vars[i].type == FUNCTION)
317     sprintf(sbuf, "%s(x)=", vars[i].name);
318     else
319     sprintf(sbuf, "%s=", vars[i].name);
320     j = strlen(sbuf);
321 schorsch 1.3 clearerr(stdin); fgets(sbuf+j, sizeof(sbuf)-j, stdin);
322 greg 1.1 if (sbuf[j]) {
323     if (vars[i].type == DATA && sbuf[j] == '-')
324     sbuf[j] = '\0';
325    
326     if (setjmp(env) == 0) {
327     recover = 1;
328     setmgvar("variable set", stdin, sbuf);
329     recover = 0;
330     } else
331     uwait();
332     }
333     }
334     }
335    
336    
337 schorsch 1.3 static void
338     gcompute(void) /* do a computation */
339 greg 1.1 {
340     char sbuf[64];
341     int i;
342    
343     printf("\nCOMPUTE\n");
344    
345     for (i = 0; i < NCAL; i++)
346     printf("\t%d %s\n", i+1, cal[i].descrip);
347    
348     printf("\nChoice (0): ");
349 schorsch 1.3 clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
350 greg 1.1 i = atoi(sbuf) - 1;
351     if (i < 0 || i >= NCAL)
352     return;
353     printf("\n");
354     if (setjmp(env) == 0) {
355     recover = 1;
356     gcalc(cal[i].value);
357     recover = 0;
358     }
359     printf("\n");
360     uwait();
361     }
362    
363    
364 schorsch 1.3 static void
365     uwait(void) /* wait for user after command, error */
366 greg 1.1 {
367     printf("Hit return to continue: ");
368     while (getchar() != '\n')
369     ;
370     }