Annotation of OpenXM_contrib2/asir2000/plot/plotf.c, Revision 1.8
1.4 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.5 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.4 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.8 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/plotf.c,v 1.7 2000/11/09 01:51:13 noro Exp $
1.4 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "ox.h"
53: #include "ifplot.h"
54:
55: void Pifplot(), Pconplot(), Pplotover(), Pplot(), Parrayplot(), Pdrawcircle();
1.6 noro 56: void Popen_canvas(), Pclear_canvas(), Pdraw_obj();
1.1 noro 57:
58: struct ftab plot_tab[] = {
59: {"ifplot",Pifplot,-7},
60: {"conplot",Pconplot,-8},
61: {"plot",Pplot,-6},
62: {"plotover",Pplotover,3},
63: {"drawcircle",Pdrawcircle,5},
1.6 noro 64: {"open_canvas",Popen_canvas,-3},
65: {"clear_canvas",Pclear_canvas,2},
1.7 noro 66: {"draw_obj",Pdraw_obj,-4},
1.1 noro 67: /*
68: {"arrayplot",Parrayplot,2},
69: */
70: {0,0,0},
71: };
72:
73: int current_s;
74:
1.6 noro 75: void Popen_canvas(arg,rp)
76: NODE arg;
77: Obj *rp;
78: {
79: Q w300,sid;
80: LIST geom;
81: int stream,id,i;
82: NODE n,n0;
83: STRING fname,wname;
84:
85: geom = 0; wname = 0; stream = -1;
86: for ( ; arg; arg = NEXT(arg) )
87: if ( !BDY(arg) )
88: stream = 0;
89: else
90: switch ( OID(BDY(arg)) ) {
91: case O_LIST:
92: geom = (LIST)BDY(arg);
93: break;
94: case O_N:
95: stream = QTOS((Q)BDY(arg)); break;
96: case O_STR:
97: wname = (STRING)BDY(arg); break;
98: default:
99: error("open_canvas : invalid argument"); break;
100: }
101: /* open_canvas in ox_plot requires
102: [sid (Q),
103: geom=[xsize,ysize] (LIST),
104: wname=name (STRING)]
105: */
106:
107: if ( stream < 0 )
108: stream = current_s;
109: else
110: current_s = stream;
111: STOQ(stream,sid);
112: if ( !geom ) {
113: STOQ(300,w300);
114: MKNODE(n0,w300,0); MKNODE(n,w300,n0); MKLIST(geom,n);
115: }
116: MKSTR(fname,"open_canvas");
117: arg = mknode(4,sid,fname,geom,wname);
118: Pox_cmo_rpc(arg,rp);
119: }
120:
1.1 noro 121: void Pifplot(arg,rp)
122: NODE arg;
123: Obj *rp;
124: {
125: Q m2,p2,w300,sid;
126: NODE defrange;
127: LIST xrange,yrange,range[2],list,geom;
128: VL vl,vl0;
129: V v[2],av[2];
130: int stream,ri,id,i;
131: P poly;
132: P var;
133: NODE n,n0;
134: STRING fname,wname;
135:
136: STOQ(-2,m2); STOQ(2,p2);
137: MKNODE(n,p2,0); MKNODE(defrange,m2,n);
138: poly = 0; vl = 0; geom = 0; wname = 0; stream = -1; ri = 0;
139: for ( ; arg; arg = NEXT(arg) )
140: if ( !BDY(arg) )
141: stream = 0;
142: else
143: switch ( OID(BDY(arg)) ) {
144: case O_P:
145: poly = (P)BDY(arg);
146: get_vars_recursive(poly,&vl);
147: for ( vl0 = vl, i = 0; vl0; vl0 = NEXT(vl0) )
148: if ( vl0->v->attr == V_IND )
149: if ( i >= 2 )
150: error("ifplot : invalid argument");
151: else
152: v[i++] = vl0->v;
153: break;
154: case O_LIST:
155: list = (LIST)BDY(arg);
156: if ( OID(BDY(BDY(list))) == O_P )
157: if ( ri > 1 )
158: error("ifplot : invalid argument");
159: else
160: range[ri++] = list;
161: else
162: geom = list;
163: break;
164: case O_N:
165: stream = QTOS((Q)BDY(arg)); break;
166: case O_STR:
167: wname = (STRING)BDY(arg); break;
168: default:
169: error("ifplot : invalid argument"); break;
170: }
171: if ( !poly )
172: error("ifplot : invalid argument");
173: switch ( ri ) {
174: case 0:
175: if ( !v[1] )
176: error("ifplot : please specify all variables");
177: MKV(v[0],var); MKNODE(n,var,defrange); MKLIST(xrange,n);
178: MKV(v[1],var); MKNODE(n,var,defrange); MKLIST(yrange,n);
179: break;
180: case 1:
181: if ( !v[1] )
182: error("ifplot : please specify all variables");
183: av[0] = VR((P)BDY(BDY(range[0])));
184: if ( v[0] == av[0] ) {
185: xrange = range[0];
186: MKV(v[1],var); MKNODE(n,var,defrange); MKLIST(yrange,n);
187: } else if ( v[1] == av[0] ) {
188: MKV(v[0],var); MKNODE(n,var,defrange); MKLIST(xrange,n);
189: yrange = range[0];
190: } else
191: error("ifplot : invalid argument");
192: break;
193: case 2:
194: av[0] = VR((P)BDY(BDY(range[0])));
195: av[1] = VR((P)BDY(BDY(range[1])));
196: if ( ((v[0] == av[0]) && (!v[1] || v[1] == av[1])) ||
197: ((v[0] == av[1]) && (!v[1] || v[1] == av[0])) ) {
198: xrange = range[0]; yrange = range[1];
199: } else
200: error("ifplot : invalid argument");
201: break;
202: default:
203: error("ifplot : cannot happen"); break;
204: }
205: /* ifplot in ox_plot requires
206: [sid (Q),
207: formula (Obj),
208: xrange=[x,xmin,xmax] (LIST),
209: yrange=[y,ymin,ymax] (LIST),
210: zrange=0,
211: geom=[xsize,ysize] (LIST),
212: wname=name (STRING)]
213: */
214:
215: if ( stream < 0 )
216: stream = current_s;
217: else
218: current_s = stream;
219: STOQ(stream,sid);
220: if ( !geom ) {
221: STOQ(300,w300);
222: MKNODE(n0,w300,0); MKNODE(n,w300,n0); MKLIST(geom,n);
223: }
224: MKSTR(fname,"plot");
225: arg = mknode(8,sid,fname,poly,xrange,yrange,0,geom,wname);
1.3 noro 226: Pox_rpc(arg,rp);
1.1 noro 227: }
228:
229: void Pconplot(arg,rp)
230: NODE arg;
231: Obj *rp;
232: {
233: Q m2,p2,w300,sid;
234: NODE defrange;
235: LIST xrange,yrange,zrange,range[3],list,geom;
236: VL vl,vl0;
237: V v[2],av[2];
238: int stream,ri,id,i;
239: P poly;
240: P var;
241: NODE n,n0;
242: STRING fname,wname;
243:
244: STOQ(-2,m2); STOQ(2,p2);
245: MKNODE(n,p2,0); MKNODE(defrange,m2,n);
246: poly = 0; vl = 0; geom = 0; wname = 0; stream = -1; ri = 0;
247: for ( ; arg; arg = NEXT(arg) )
248: if ( !BDY(arg) )
249: stream = 0;
250: else
251: switch ( OID(BDY(arg)) ) {
252: case O_P:
253: poly = (P)BDY(arg);
254: get_vars_recursive(poly,&vl);
255: for ( vl0 = vl, i = 0; vl0; vl0 = NEXT(vl0) )
256: if ( vl0->v->attr == V_IND )
257: if ( i >= 2 )
258: error("ifplot : invalid argument");
259: else
260: v[i++] = vl0->v;
261: break;
262: case O_LIST:
263: list = (LIST)BDY(arg);
264: if ( OID(BDY(BDY(list))) == O_P )
265: if ( ri > 2 )
266: error("ifplot : invalid argument");
267: else
268: range[ri++] = list;
269: else
270: geom = list;
271: break;
272: case O_N:
273: stream = QTOS((Q)BDY(arg)); break;
274: case O_STR:
275: wname = (STRING)BDY(arg); break;
276: default:
277: error("ifplot : invalid argument"); break;
278: }
279: if ( !poly )
280: error("ifplot : invalid argument");
281: switch ( ri ) {
282: case 0:
283: if ( !v[1] )
284: error("ifplot : please specify all variables");
285: MKV(v[0],var); MKNODE(n,var,defrange); MKLIST(xrange,n);
286: MKV(v[1],var); MKNODE(n,var,defrange); MKLIST(yrange,n);
287: MKNODE(n,0,defrange); MKLIST(zrange,n);
288: break;
289: case 1:
290: if ( !v[1] )
291: error("ifplot : please specify all variables");
292: av[0] = VR((P)BDY(BDY(range[0])));
293: if ( v[0] == av[0] ) {
294: xrange = range[0];
295: MKV(v[1],var); MKNODE(n,var,defrange); MKLIST(yrange,n);
296: MKNODE(n,0,defrange); MKLIST(zrange,n);
297: } else if ( v[1] == av[0] ) {
298: MKV(v[0],var); MKNODE(n,var,defrange); MKLIST(xrange,n);
299: yrange = range[0];
300: MKNODE(n,0,defrange); MKLIST(zrange,n);
301: } else {
302: MKV(v[0],var); MKNODE(n,var,defrange); MKLIST(xrange,n);
303: MKV(v[1],var); MKNODE(n,var,defrange); MKLIST(yrange,n);
304: zrange = range[0];
305: }
306: break;
307: case 2: case 3:
308: av[0] = VR((P)BDY(BDY(range[0])));
309: av[1] = VR((P)BDY(BDY(range[1])));
310: if ( ((v[0] == av[0]) && (!v[1] || v[1] == av[1])) ||
311: ((v[0] == av[1]) && (!v[1] || v[1] == av[0])) ) {
312: xrange = range[0]; yrange = range[1];
313: if ( ri == 3 )
314: zrange = range[2];
315: else {
316: MKNODE(n,0,defrange); MKLIST(zrange,n);
317: }
318: } else
319: error("ifplot : invalid argument");
320: break;
321: default:
322: error("ifplot : cannot happen"); break;
323: }
324: if ( stream < 0 )
325: stream = current_s;
326: else
327: current_s = stream;
328:
329: /* conplot in ox_plot requires
330: [sid (Q),
331: formula (Obj),
332: xrange=[x,xmin,xmax] (LIST),
333: yrange=[y,ymin,ymax] (LIST),
334: zrange=[z,zmin,zmax] (LIST),
335: geom=[xsize,ysize] (LIST),
336: wname=name (STRING)]
337: */
338:
339: if ( stream < 0 )
340: stream = current_s;
341: else
342: current_s = stream;
343: STOQ(stream,sid);
344: if ( !geom ) {
345: STOQ(300,w300);
346: MKNODE(n0,w300,0); MKNODE(n,w300,n0); MKLIST(geom,n);
347: }
348: MKSTR(fname,"plot");
349: arg = mknode(8,sid,fname,poly,xrange,yrange,zrange,geom,wname);
1.3 noro 350: Pox_rpc(arg,rp);
1.1 noro 351: }
352:
353: void Pplot(arg,rp)
354: NODE arg;
355: Obj *rp;
356: {
357: Q m2,p2,w300,sid;
358: NODE defrange;
359: LIST xrange,range[1],list,geom;
360: VL vl,vl0;
361: V v[1],av[1];
362: int stream,ri,id,i;
363: P poly;
364: P var;
365: NODE n,n0;
366: STRING fname,wname;
367:
368: STOQ(-2,m2); STOQ(2,p2);
369: MKNODE(n,p2,0); MKNODE(defrange,m2,n);
370: poly = 0; vl = 0; geom = 0; wname = 0; stream = -1; ri = 0;
371: for ( ; arg; arg = NEXT(arg) )
372: if ( !BDY(arg) )
373: stream = 0;
374: else
375: switch ( OID(BDY(arg)) ) {
376: case O_P: case O_R:
377: poly = (P)BDY(arg);
378: get_vars_recursive(poly,&vl);
379: for ( vl0 = vl, i = 0; vl0; vl0 = NEXT(vl0) )
380: if ( vl0->v->attr == V_IND )
381: if ( i >= 1 )
382: error("ifplot : invalid argument");
383: else
384: v[i++] = vl0->v;
1.8 ! noro 385: if ( i != 1 )
! 386: error("ifplot : invalid argument");
1.1 noro 387: break;
388: case O_LIST:
389: list = (LIST)BDY(arg);
390: if ( OID(BDY(BDY(list))) == O_P )
391: if ( ri > 0 )
392: error("plot : invalid argument");
393: else
394: range[ri++] = list;
395: else
396: geom = list;
397: break;
398: case O_N:
399: stream = QTOS((Q)BDY(arg)); break;
400: case O_STR:
401: wname = (STRING)BDY(arg); break;
402: default:
403: error("plot : invalid argument"); break;
404: }
405: if ( !poly )
406: error("plot : invalid argument");
407: switch ( ri ) {
408: case 0:
409: MKV(v[0],var); MKNODE(n,var,defrange); MKLIST(xrange,n);
410: break;
411: case 1:
412: av[0] = VR((P)BDY(BDY(range[0])));
413: if ( v[0] == av[0] )
414: xrange = range[0];
415: else
416: error("plot : invalid argument");
417: break;
418: default:
419: error("plot : cannot happen"); break;
420: }
421: /* conplot in ox_plot requires
422: [sid (Q),
423: formula (Obj),
424: xrange=[x,xmin,xmax] (LIST),
425: yrange=0,
426: zrange=0,
427: geom=[xsize,ysize] (LIST),
428: wname=name (STRING)]
429: */
430: if ( stream < 0 )
431: stream = current_s;
432: else
433: current_s = stream;
434: STOQ(stream,sid);
435: if ( !geom ) {
436: STOQ(300,w300);
437: MKNODE(n0,w300,0); MKNODE(n,w300,n0); MKLIST(geom,n);
438: }
439: MKSTR(fname,"plot");
440: arg = mknode(8,sid,fname,poly,xrange,0,0,geom,wname);
1.3 noro 441: Pox_rpc(arg,rp);
1.1 noro 442: }
443:
444: void Pplotover(arg,rp)
445: NODE arg;
446: Obj *rp;
447: {
448: Q sid,index;
449: P poly;
450: STRING fname;
451:
452: poly = (P)ARG0(arg);
453: sid = (Q)ARG1(arg);
454: index = (Q)ARG2(arg);
455: MKSTR(fname,"plotover");
456: arg = mknode(4,sid,fname,index,poly);
1.3 noro 457: Pox_rpc(arg,rp);
1.1 noro 458: }
459:
460: /* arg = [x,y,r,sid,index] */
461:
462: void Pdrawcircle(arg,rp)
463: NODE arg;
464: Obj *rp;
465: {
466: Q sid,index;
467: Obj x,y,r;
468: STRING fname;
469: NODE n;
470: LIST pos;
471:
472: x = (Obj)ARG0(arg);
473: y = (Obj)ARG1(arg);
474: r = (Obj)ARG2(arg);
475: sid = (Q)ARG3(arg);
476: index = (Q)ARG4(arg);
477: MKSTR(fname,"drawcircle");
478: n = mknode(3,x,y,r); MKLIST(pos,n);
479: arg = mknode(4,sid,fname,index,pos);
1.3 noro 480: Pox_rpc(arg,rp);
1.6 noro 481: }
482:
483: /* draw_obj(sid,cindex,point|line); point = [x,y], line = [xa,ya,xb,yb] */
484: void Pdraw_obj(arg,rp)
485: NODE arg;
486: Obj *rp;
487: {
488: static STRING fname;
489: Q sid,index;
490: LIST obj;
491:
492: if ( !fname ) {
493: MKSTR(fname,"draw_obj");
494: }
495: sid = (Q)ARG0(arg);
496: index = (Q)ARG1(arg);
497: obj = (LIST)ARG2(arg);
1.7 noro 498: /* ARG3(arg) = color */
499: if ( argc(arg) == 4 )
500: arg = mknode(5,sid,fname,index,obj,ARG3(arg));
501: else
502: arg = mknode(4,sid,fname,index,obj);
1.6 noro 503: Pox_cmo_rpc(arg,rp);
504: }
505:
506: void Pclear_canvas(arg,rp)
507: NODE arg;
508: Obj *rp;
509: {
510: static STRING fname;
511: Q sid,index;
512: LIST obj;
513:
514: if ( !fname ) {
515: MKSTR(fname,"clear_canvas");
516: }
517: sid = (Q)ARG0(arg);
518: index = (Q)ARG1(arg);
519: arg = mknode(3,sid,fname,index);
520: Pox_cmo_rpc(arg,rp);
1.1 noro 521: }
522:
523: #if 0
524: void Parrayplot(arg,rp)
525: NODE arg;
526: Obj *rp;
527: {
528: int s;
529: int id;
530:
531: if ( ID((Obj)ARG0(arg)) == O_VECT && ID((Obj)ARG1(arg)) == O_LIST ) {
532: s = current_s;
533: gensend(s,C_APLOT,0);
534: gensend(s,C_OBJ,ARG0(arg)); gensend(s,C_OBJ,ARG1(arg)); genflush(s);
535: }
536: genrecv(s,&id,rp);
537: }
538: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>