ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/igraph.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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