Annotation of OpenXM_contrib2/asir2000/plot/if.c, Revision 1.13
1.2 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.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 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.13 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/if.c,v 1.12 2002/08/02 08:59:47 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "ox.h"
53: #include "ifplot.h"
54:
1.8 noro 55: extern JMP_BUF ox_env;
1.1 noro 56:
1.4 noro 57: int open_canvas(NODE arg)
58: {
59: int id;
60: struct canvas *can;
61: LIST wsize;
62: STRING wname;
63:
64: wsize = (LIST)ARG0(arg);
65: wname = (STRING)ARG1(arg);
66:
67: can = canvas[id = search_canvas()];
68: can->mode = MODE_INTERACTIVE;
69: if ( !wsize ) {
70: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
71: } else {
72: can->width = QTOS((Q)BDY(BDY(wsize)));
73: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
74: }
75: if ( wname )
76: can->wname = BDY(wname);
77: else
78: can->wname = "";
79: create_canvas(can);
80: return id;
81: }
82:
1.1 noro 83: int plot(NODE arg)
84: {
85: int id;
86: NODE n;
87: struct canvas *can;
88: P formula;
89: LIST xrange,yrange,zrange,wsize;
90: STRING wname;
1.12 noro 91: V v;
1.1 noro 92:
93: formula = (P)ARG0(arg);
94: xrange = (LIST)ARG1(arg);
95: yrange = (LIST)ARG2(arg);
96: zrange = (LIST)ARG3(arg);
97: wsize = (LIST)ARG4(arg);
98: wname = (STRING)ARG5(arg);
99:
100: can = canvas[id = search_canvas()];
1.12 noro 101: if ( xrange ) {
102: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
103: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
104: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
105: }
1.1 noro 106: if ( yrange ) {
107: n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
108: can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
109: can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
1.12 noro 110: }
111: if ( xrange && yrange )
112: can->mode = zrange ? MODE_CONPLOT : MODE_IFPLOT;
113: else
114: can->mode = xrange ? MODE_PLOT : MODE_POLARPLOT;
115:
116: if ( zrange ) {
117: n = BDY(zrange); v = VR((P)BDY(n)); n = NEXT(n);
118: can->zmin = ToReal(BDY(n));
119: n = NEXT(n); can->zmax = ToReal(BDY(n));
120: n = NEXT(n);
121: if ( can->mode == MODE_CONPLOT )
122: can->nzstep = n ? QTOS((Q)BDY(n)) : MAXGC;
123: else {
124: /* XXX */
125: can->vx = v;
126: can->nzstep = n ? QTOS((Q)BDY(n)) : DEFAULTPOLARSTEP;
127: }
128: }
129:
1.1 noro 130: if ( !wsize ) {
131: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
132: } else {
133: can->width = QTOS((Q)BDY(BDY(wsize)));
134: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
135: }
136: if ( wname )
137: can->wname = BDY(wname);
138: else
139: can->wname = "";
140: can->formula = formula;
141: create_canvas(can);
142: if ( can->mode == MODE_PLOT ) {
143: plotcalc(can);
144: plot_print(display,can);
1.12 noro 145: } else if ( can->mode == MODE_POLARPLOT ) {
146: polarplotcalc(can);
147: plot_print(display,can);
1.1 noro 148: } else
149: ifplotmain(can);
1.12 noro 150: copy_to_canvas(can);
151: return id;
152: }
153:
154: int polarplot(NODE arg)
155: {
156: int id;
157: NODE n;
158: struct canvas *can;
159: P formula;
160: LIST xrange,yrange,zrange,wsize;
161: STRING wname;
162:
163: formula = (P)ARG0(arg);
164: xrange = (LIST)ARG1(arg);
165: wsize = (LIST)ARG4(arg);
166: wname = (STRING)ARG5(arg);
167:
168: can = canvas[id = search_canvas()];
169: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
170: /* XXX use zmin, zmax to hold parameter range */
171: can->zmin = ToReal((Num)BDY(n)); n = NEXT(n);
172: can->zmax = ToReal((Num)BDY(n));
173: can->mode = MODE_POLARPLOT;
174: if ( !wsize ) {
175: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
176: } else {
177: can->width = QTOS((Q)BDY(BDY(wsize)));
178: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
179: }
180: if ( wname )
181: can->wname = BDY(wname);
182: else
183: can->wname = "";
184: can->formula = formula;
1.13 ! noro 185: polarplotcalc(can);
! 186: /* xmax, xmin etc are determined after calc */
1.12 noro 187: create_canvas(can);
188: plot_print(display,can);
1.1 noro 189: copy_to_canvas(can);
190: return id;
191: }
192:
1.6 noro 193: int memory_plot(NODE arg,LIST *bytes)
194: {
195: NODE n;
196: struct canvas tmp_can;
197: struct canvas *can;
198: P formula;
199: LIST xrange,yrange,zrange,wsize;
200: int width,height;
201: double **tabe;
202: int i;
203: BYTEARRAY barray;
204: Q qw,qh;
205:
206: formula = (P)ARG0(arg);
207: xrange = (LIST)ARG1(arg);
208: yrange = (LIST)ARG2(arg);
209: zrange = (LIST)ARG3(arg);
210: wsize = (LIST)ARG4(arg);
211:
212: can = &tmp_can;
213: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
214: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
215: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
216: if ( yrange ) {
217: n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
218: can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
219: can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
220: if ( zrange ) {
221: n = NEXT(BDY(zrange));
222: can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
223: if ( n = NEXT(n) )
224: can->nzstep = QTOS((Q)BDY(n));
225: else
226: can->nzstep = MAXGC;
227: can->mode = MODE_CONPLOT;
228: } else
229: can->mode = MODE_IFPLOT;
230: } else
231: can->mode = MODE_PLOT;
232: if ( !wsize ) {
233: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
234: } else {
235: can->width = QTOS((Q)BDY(BDY(wsize)));
236: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
237: }
238: can->wname = "";
239: can->formula = formula;
240: if ( can->mode == MODE_PLOT )
241: plotcalc(can);
242: else {
243: width = can->width; height = can->height;
244: tabe = (double **)ALLOCA(width*sizeof(double *));
245: for ( i = 0; i < width; i++ )
246: tabe[i] = (double *)ALLOCA(height*sizeof(double));
247: calc(tabe,can,1);
248: memory_if_print(tabe,can,&barray);
249: STOQ(width,qw); STOQ(height,qh);
250: n = mknode(3,qw,qh,barray);
251: MKLIST(*bytes,n);
252: }
253: }
254:
1.1 noro 255: int plotover(NODE arg)
256: {
257: int index;
258: P formula;
259: struct canvas *can;
260: struct canvas fakecan;
261: VL vl,vl0;
262:
263: index = QTOS((Q)ARG0(arg));
264: formula = (P)ARG1(arg);
265: can = canvas[index];
266: if ( !can->window )
267: return -1;
1.7 noro 268: get_vars_recursive((Obj)formula,&vl);
1.1 noro 269: for ( vl0 = vl; vl0; vl0 = NEXT(vl0) )
1.7 noro 270: if ( vl0->v->attr == (pointer)V_IND )
1.1 noro 271: if ( vl->v != can->vx && vl->v != can->vy )
272: return -1;
273: current_can = can;
274: fakecan = *can; fakecan.formula = formula;
275: if ( can->mode == MODE_PLOT ) {
276: plotcalc(&fakecan);
277: plot_print(display,&fakecan);
278: } else
279: ifplotmain(&fakecan);
280: copy_to_canvas(&fakecan);
281: return index;
282: }
283:
284: int drawcircle(NODE arg)
285: {
1.4 noro 286: #if !defined(VISUAL)
1.1 noro 287: int id;
288: int index;
289: pointer ptr;
290: Q ret;
291: LIST xyr;
292: Obj x,y,r;
293: int wx,wy,wr;
294: struct canvas *can;
295: struct canvas fakecan;
296:
297: index = QTOS((Q)ARG0(arg));
298: xyr = (LIST)ARG1(arg);
299: x = (Obj)ARG0(BDY(xyr)); y = (Obj)ARG1(BDY(xyr)); r = (Obj)ARG2(BDY(xyr));
300: can = canvas[index];
301: if ( !can->window )
302: return -1;
303: else {
304: current_can = can;
305: wx = (ToReal(x)-can->xmin)*can->width/(can->xmax-can->xmin);
306: wy = (can->ymax-ToReal(y))*can->height/(can->ymax-can->ymin);
307: wr = ToReal(r);
308: XFillArc(display,can->pix,colorGC,wx-wr/2,wy-wr/2,wr,wr,0,360*64);
309: copy_to_canvas(can);
310: return index;
311: }
1.4 noro 312: #endif
313: }
314:
315: int draw_obj(NODE arg)
316: {
317: int index;
1.5 noro 318: int x,y,u,v,len,r;
1.4 noro 319: NODE obj,n;
320: RealVect *vect;
321: struct canvas *can;
1.5 noro 322: int color;
1.4 noro 323:
324: index = QTOS((Q)ARG0(arg));
325: can = canvas[index];
1.10 noro 326: if ( !can && closed_canvas[index] ) {
327: canvas[index] = closed_canvas[index];
328: closed_canvas[index] = 0;
329: can = canvas[index];
330: popup_canvas(index);
331: current_can = can;
332: } else if ( !can || (can && !can->window) ) {
1.5 noro 333: set_lasterror("draw_obj : canvas does not exist");
1.4 noro 334: return -1;
1.5 noro 335: }
1.4 noro 336:
337: obj = BDY((LIST)ARG1(arg));
1.5 noro 338: if ( argc(arg) == 3 )
339: color = QTOS((Q)ARG2(arg));
340: else
341: color = 0; /* black */
342: switch ( len = length(obj) ) {
1.4 noro 343: case 2: /* point */
344: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
1.5 noro 345: draw_point(display,can,x,y,color);
346: MKRVECT2(vect,x,y); MKNODE(n,vect,can->history); can->history = n;
347: break;
348: case 3: /* circle */
349: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
350: r = (int)ToReal((Q)ARG2(obj));
351: MKRVECT3(vect,x,y,r); MKNODE(n,vect,can->history); can->history = n;
1.4 noro 352: break;
353: case 4: /* line */
354: x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
355: u = (int)ToReal((Q)ARG2(obj)); v = (int)ToReal((Q)ARG3(obj));
1.5 noro 356: draw_line(display,can,x,y,u,v,color);
1.4 noro 357: MKRVECT4(vect,x,y,u,v); MKNODE(n,vect,can->history); can->history = n;
358: break;
359: default:
1.5 noro 360: set_lasterror("draw_obj : invalid request");
1.4 noro 361: return -1;
362: }
1.9 noro 363: return 0;
364: }
365:
366: int draw_string(NODE arg)
367: {
368: int index,x,y;
369: char *str;
370: NODE pos;
371: struct canvas *can;
372: int color;
373:
374: index = QTOS((Q)ARG0(arg));
375: can = canvas[index];
1.11 noro 376: if ( !can && closed_canvas[index] ) {
377: canvas[index] = closed_canvas[index];
378: closed_canvas[index] = 0;
379: can = canvas[index];
380: popup_canvas(index);
381: current_can = can;
382: } else if ( !can || (can && !can->window) ) {
383: set_lasterror("draw_obj : canvas does not exist");
1.9 noro 384: return -1;
385: }
386:
387: pos = BDY((LIST)ARG1(arg));
388: str = BDY((STRING)ARG2(arg));
389: if ( argc(arg) == 4 )
390: color = QTOS((Q)ARG3(arg));
391: else
392: color = 0; /* black */
393: x = (int)ToReal((Q)ARG0(pos));
394: y = (int)ToReal((Q)ARG1(pos));
395: draw_character_string(display,can,x,y,str,color);
1.4 noro 396: return 0;
397: }
398:
399: int clear_canvas(NODE arg)
400: {
401: int index;
402: struct canvas *can;
403:
404: index = QTOS((Q)ARG0(arg));
405: can = canvas[index];
406: if ( !can || !can->window )
407: return -1;
408: clear_pixmap(can);
409: copy_to_canvas(can);
410: /* clear the history */
411: can->history = 0;
1.1 noro 412: }
413:
414: #define RealtoDbl(r) ((r)?BDY(r):0.0)
415:
416: int arrayplot(NODE arg)
417: {
418: int id,ix,w,h;
419: VECT array;
420: LIST xrange,wsize;
421: char *wname;
422: NODE n;
423: double ymax,ymin,dy,xstep;
424: Real *tab;
425: struct canvas *can;
426: POINT *pa;
427:
428: array = (VECT)ARG0(arg);
429: xrange = (LIST)ARG1(arg);
430: can = canvas[id = search_canvas()];
431: n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
432: can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
433: can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
434: if ( !wsize ) {
435: can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
436: } else {
437: can->width = QTOS((Q)BDY(BDY(wsize)));
438: can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
439: }
440: can->wname = wname; can->formula = 0; can->mode = MODE_PLOT;
441: create_canvas(can);
442: w = array->len;
443: h = can->height;
444: tab = (Real *)BDY(array);
445: if ( can->ymax == can->ymin ) {
446: for ( ymax = ymin = RealtoDbl(tab[0]), ix = 1; ix < w; ix++ ) {
447: if ( RealtoDbl(tab[ix]) > ymax )
448: ymax = RealtoDbl(tab[ix]);
449: if ( RealtoDbl(tab[ix]) < ymin )
450: ymin = RealtoDbl(tab[ix]);
451: }
452: can->ymax = ymax; can->ymin = ymin;
453: } else {
454: ymax = can->ymax; ymin = can->ymin;
455: }
456: dy = ymax-ymin;
457: can->pa = (struct pa *)MALLOC(sizeof(struct pa));
458: can->pa[0].length = w;
459: can->pa[0].pos = pa = (POINT *)MALLOC(w*sizeof(POINT));
460: xstep = (double)can->width/(double)(w-1);
461: for ( ix = 0; ix < w; ix++ ) {
462: #ifndef MAXSHORT
463: #define MAXSHORT ((short)0x7fff)
464: #endif
465: double t;
466:
467: pa[ix].x = (int)(ix*xstep);
468: t = (h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
469: if ( t > MAXSHORT )
470: pa[ix].y = MAXSHORT;
471: else if ( t < -MAXSHORT )
472: pa[ix].y = -MAXSHORT;
473: else
1.7 noro 474: pa[ix].y = (long)t;
1.1 noro 475: }
476: plot_print(display,can);
477: copy_to_canvas(can);
478: return id;
479: }
480:
1.7 noro 481: void ifplot_resize(struct canvas *can,POINT spos,POINT epos)
1.1 noro 482: {
483: struct canvas *ncan;
484: struct canvas fakecan;
485: Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
486: Q sx,sy,ex,ey,cw,ch,ten,two;
487: Q s,t;
488: int new;
489: int w,h,m;
490:
491: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
492: if ( can->precise && !can->wide ) {
493: fakecan = *can; ncan = &fakecan;
494: } else {
495: new = search_canvas(); ncan = canvas[new];
496: }
497: ncan->mode = can->mode;
498: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
499: ncan->nzstep = can->nzstep;
500: ncan->wname = can->wname;
501: ncan->vx = can->vx; ncan->vy = can->vy;
502: ncan->formula = can->formula;
503: w = XC(epos)-XC(spos);
504: h = YC(epos)-YC(spos);
505: m = MAX(can->width,can->height);
506: if ( can->precise ) {
507: ncan->width = w; ncan->height = h;
508: } else if ( w > h ) {
509: ncan->width = m; ncan->height = m * h/w;
510: } else {
511: ncan->width = m * w/h; ncan->height = m;
512: }
513: if ( can->wide ) {
514: STOQ(10,ten); STOQ(2,two);
515: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
516: subq(can->qymax,can->qymin,&t); mulq(t,ten,&dy);
517: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
518: addq(can->qymax,can->qymin,&t); divq(t,two,&ymid);
519: divq(dx,two,&dx2); divq(dy,two,&dy2);
520: subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
521: subq(ymid,dy2,&ymin); addq(ymid,dy2,&ymax);
522: } else {
523: subq(can->qxmax,can->qxmin,&dx); subq(can->qymax,can->qymin,&dy);
524: xmin = can->qxmin; xmax = can->qxmax;
525: ymin = can->qymin; ymax = can->qymax;
526: }
527: STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
528: STOQ(can->width,cw); STOQ(can->height,ch);
529: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
530: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
531: mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
532: mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
533: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
534: ncan->ymin = ToReal(ncan->qymin); ncan->ymax = ToReal(ncan->qymax);
535: if ( can->precise && !can->wide ) {
536: current_can = can;
537: alloc_pixmap(ncan);
1.4 noro 538: #if defined(VISUAL)
539: ncan->real_can = can;
540: #endif
1.1 noro 541: qifplotmain(ncan);
542: copy_subimage(ncan,can,spos);
543: copy_to_canvas(can);
544: } else {
545: create_canvas(ncan);
546: if ( can->precise )
547: qifplotmain(ncan);
548: else
549: ifplotmain(ncan);
550: copy_to_canvas(ncan);
551: }
552: }
553: }
554:
1.7 noro 555: void plot_resize(struct canvas *can,POINT spos,POINT epos)
1.1 noro 556: {
557: struct canvas *ncan;
558: Q dx,dx2,xmin,xmax,xmid;
1.7 noro 559: double dy,ymin,ymax,ymid;
1.1 noro 560: Q sx,ex,cw,ten,two;
561: Q s,t;
562: int new;
563: int w,h,m;
564:
565: if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
566: new = search_canvas(); ncan = canvas[new];
567: ncan->mode = can->mode;
568: ncan->zmin = can->zmin; ncan->zmax = can->zmax;
569: ncan->nzstep = can->nzstep;
570: ncan->wname = can->wname;
571: ncan->vx = can->vx; ncan->vy = can->vy;
572: ncan->formula = can->formula;
573: w = XC(epos)-XC(spos);
574: h = YC(epos)-YC(spos);
575: m = MAX(can->width,can->height);
576: if ( w > h ) {
577: ncan->width = m; ncan->height = m * h/w;
578: } else {
579: ncan->width = m * w/h; ncan->height = m;
580: }
581: if ( can->wide ) {
582: STOQ(10,ten); STOQ(2,two);
583: subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
584: addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
585: divq(dx,two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
586:
587: dy = (can->ymax-can->ymin)*10;
588: ymid = (can->ymax+can->ymin)/2;
589: ymin = ymid-dy/2; ymax = ymid+dy/2;
590: } else {
591: subq(can->qxmax,can->qxmin,&dx);
592: xmin = can->qxmin; xmax = can->qxmax;
593:
594: dy = can->ymax-can->ymin;
595: ymin = can->ymin; ymax = can->ymax;
596: }
597: STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
598: mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
599: mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
600: ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
601:
602: ncan->ymin = ymax-YC(epos)*dy/can->height;
603: ncan->ymax = ymax-YC(spos)*dy/can->height;
604:
605: create_canvas(ncan);
606: plotcalc(ncan);
607: plot_print(display,ncan);
608: copy_to_canvas(ncan);
609: }
610: }
611:
1.7 noro 612: void ifplotmain(struct canvas *can)
1.1 noro 613: {
614: int width,height;
1.7 noro 615: double **tabe;
1.1 noro 616: int i;
617:
618: width = can->width; height = can->height;
619: tabe = (double **)ALLOCA(width*sizeof(double *));
620: for ( i = 0; i < width; i++ )
621: tabe[i] = (double *)ALLOCA(height*sizeof(double));
622: define_cursor(can->window,runningcur);
623: set_busy(can); set_selection();
1.6 noro 624: calc(tabe,can,0); if_print(display,tabe,can);
1.1 noro 625: reset_selection(); reset_busy(can);
626: define_cursor(can->window,normalcur);
627: }
628:
1.7 noro 629: void qifplotmain(struct canvas *can)
1.1 noro 630: {
631: int width,height;
632: char **tabe,*tabeb;
633: int i;
634:
635: width = can->width; height = can->height;
636: tabe = (char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
1.8 noro 637: bzero((void *)tabe,width*sizeof(char *)+width*height*sizeof(char));
1.1 noro 638: for ( i = 0, tabeb = (char *)(tabe+width); i < width; i++ )
639: tabe[i] = tabeb + height*i;
640: define_cursor(can->window,runningcur);
641: set_busy(can); set_selection();
642: qcalc(tabe,can); qif_print(display,tabe,can);
643: reset_selection(); reset_busy(can);
644: define_cursor(can->window,normalcur);
645: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>