[BACK]Return to if.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / plot

Annotation of OpenXM_contrib2/asir2000/plot/if.c, Revision 1.6

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.6     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/if.c,v 1.5 2000/11/09 01:51:12 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:
                     55: extern jmp_buf ox_env;
                     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;
                     91:
                     92:        formula = (P)ARG0(arg);
                     93:        xrange = (LIST)ARG1(arg);
                     94:        yrange = (LIST)ARG2(arg);
                     95:        zrange = (LIST)ARG3(arg);
                     96:        wsize = (LIST)ARG4(arg);
                     97:        wname = (STRING)ARG5(arg);
                     98:
                     99:        can = canvas[id = search_canvas()];
                    100:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
                    101:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
                    102:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
                    103:        if ( yrange ) {
                    104:                n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
                    105:                can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
                    106:                can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
                    107:                if ( zrange ) {
                    108:                        n = NEXT(BDY(zrange));
                    109:                        can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
                    110:                        if ( n = NEXT(n) )
                    111:                                can->nzstep = QTOS((Q)BDY(n));
                    112:                        else
                    113:                                can->nzstep = MAXGC;
                    114:                        can->mode = MODE_CONPLOT;
                    115:                } else
                    116:                        can->mode = MODE_IFPLOT;
                    117:        } else
                    118:                can->mode = MODE_PLOT;
                    119:        if ( !wsize ) {
                    120:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                    121:        } else {
                    122:                can->width = QTOS((Q)BDY(BDY(wsize)));
                    123:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                    124:        }
                    125:        if ( wname )
                    126:                can->wname = BDY(wname);
                    127:        else
                    128:                can->wname = "";
                    129:        can->formula = formula;
                    130:        create_canvas(can);
                    131:        if ( can->mode == MODE_PLOT ) {
                    132:                plotcalc(can);
                    133:                plot_print(display,can);
                    134:        } else
                    135:                ifplotmain(can);
                    136:        copy_to_canvas(can);
                    137:        return id;
                    138: }
                    139:
1.6     ! noro      140: int memory_plot(NODE arg,LIST *bytes)
        !           141: {
        !           142:        int id;
        !           143:        NODE n;
        !           144:        struct canvas tmp_can;
        !           145:        struct canvas *can;
        !           146:        P formula;
        !           147:        LIST xrange,yrange,zrange,wsize;
        !           148:        int width,height;
        !           149:        double **tabe;
        !           150:        int i;
        !           151:        BYTEARRAY barray;
        !           152:        Q qw,qh;
        !           153:
        !           154:        formula = (P)ARG0(arg);
        !           155:        xrange = (LIST)ARG1(arg);
        !           156:        yrange = (LIST)ARG2(arg);
        !           157:        zrange = (LIST)ARG3(arg);
        !           158:        wsize = (LIST)ARG4(arg);
        !           159:
        !           160:        can = &tmp_can;
        !           161:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
        !           162:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
        !           163:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
        !           164:        if ( yrange ) {
        !           165:                n = BDY(yrange); can->vy = VR((P)BDY(n)); n = NEXT(n);
        !           166:                can->qymin = (Q)BDY(n); n = NEXT(n); can->qymax = (Q)BDY(n);
        !           167:                can->ymin = ToReal(can->qymin); can->ymax = ToReal(can->qymax);
        !           168:                if ( zrange ) {
        !           169:                        n = NEXT(BDY(zrange));
        !           170:                        can->zmin = ToReal(BDY(n)); n = NEXT(n); can->zmax = ToReal(BDY(n));
        !           171:                        if ( n = NEXT(n) )
        !           172:                                can->nzstep = QTOS((Q)BDY(n));
        !           173:                        else
        !           174:                                can->nzstep = MAXGC;
        !           175:                        can->mode = MODE_CONPLOT;
        !           176:                } else
        !           177:                        can->mode = MODE_IFPLOT;
        !           178:        } else
        !           179:                can->mode = MODE_PLOT;
        !           180:        if ( !wsize ) {
        !           181:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
        !           182:        } else {
        !           183:                can->width = QTOS((Q)BDY(BDY(wsize)));
        !           184:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
        !           185:        }
        !           186:        can->wname = "";
        !           187:        can->formula = formula;
        !           188:        if ( can->mode == MODE_PLOT )
        !           189:                plotcalc(can);
        !           190:        else {
        !           191:                width = can->width; height = can->height;
        !           192:                tabe = (double **)ALLOCA(width*sizeof(double *));
        !           193:                for ( i = 0; i < width; i++ )
        !           194:                        tabe[i] = (double *)ALLOCA(height*sizeof(double));
        !           195:                calc(tabe,can,1);
        !           196:                memory_if_print(tabe,can,&barray);
        !           197:                STOQ(width,qw); STOQ(height,qh);
        !           198:                n = mknode(3,qw,qh,barray);
        !           199:                MKLIST(*bytes,n);
        !           200:        }
        !           201: }
        !           202:
1.1       noro      203: int plotover(NODE arg)
                    204: {
                    205:        int index;
                    206:        P formula;
                    207:        struct canvas *can;
                    208:        struct canvas fakecan;
                    209:        VL vl,vl0;
                    210:
                    211:        index = QTOS((Q)ARG0(arg));
                    212:        formula = (P)ARG1(arg);
                    213:        can = canvas[index];
                    214:        if ( !can->window )
                    215:                return -1;
                    216:        get_vars_recursive(formula,&vl);
                    217:        for ( vl0 = vl; vl0; vl0 = NEXT(vl0) )
                    218:                if ( vl0->v->attr == V_IND )
                    219:                        if ( vl->v != can->vx && vl->v != can->vy )
                    220:                                return -1;
                    221:        current_can = can;
                    222:        fakecan = *can; fakecan.formula = formula;
                    223:        if ( can->mode == MODE_PLOT ) {
                    224:                plotcalc(&fakecan);
                    225:                plot_print(display,&fakecan);
                    226:        } else
                    227:                ifplotmain(&fakecan);
                    228:        copy_to_canvas(&fakecan);
                    229:        return index;
                    230: }
                    231:
                    232: int drawcircle(NODE arg)
                    233: {
1.4       noro      234: #if !defined(VISUAL)
1.1       noro      235:        int id;
                    236:        int index;
                    237:        pointer ptr;
                    238:        Q ret;
                    239:        LIST xyr;
                    240:        Obj x,y,r;
                    241:        int wx,wy,wr;
                    242:        struct canvas *can;
                    243:        struct canvas fakecan;
                    244:
                    245:        index = QTOS((Q)ARG0(arg));
                    246:        xyr = (LIST)ARG1(arg);
                    247:        x = (Obj)ARG0(BDY(xyr)); y = (Obj)ARG1(BDY(xyr)); r = (Obj)ARG2(BDY(xyr));
                    248:        can = canvas[index];
                    249:        if ( !can->window )
                    250:                return -1;
                    251:        else {
                    252:                current_can = can;
                    253:                wx = (ToReal(x)-can->xmin)*can->width/(can->xmax-can->xmin);
                    254:                wy = (can->ymax-ToReal(y))*can->height/(can->ymax-can->ymin);
                    255:                wr = ToReal(r);
                    256:                XFillArc(display,can->pix,colorGC,wx-wr/2,wy-wr/2,wr,wr,0,360*64);
                    257:                copy_to_canvas(can);
                    258:                return index;
                    259:        }
1.4       noro      260: #endif
                    261: }
                    262:
                    263: int draw_obj(NODE arg)
                    264: {
                    265:        int index;
1.5       noro      266:        int x,y,u,v,len,r;
1.4       noro      267:        NODE obj,n;
                    268:        RealVect *vect;
                    269:        struct canvas *can;
1.5       noro      270:        int color;
1.4       noro      271:
                    272:        index = QTOS((Q)ARG0(arg));
                    273:        can = canvas[index];
1.5       noro      274:        if ( !can || !can->window ) {
                    275:                set_lasterror("draw_obj : canvas does not exist");
1.4       noro      276:                return -1;
1.5       noro      277:        }
1.4       noro      278:
                    279:        obj = BDY((LIST)ARG1(arg));
1.5       noro      280:        if ( argc(arg) == 3 )
                    281:                color = QTOS((Q)ARG2(arg));
                    282:        else
                    283:                color = 0; /* black */
                    284:        switch ( len = length(obj) ) {
1.4       noro      285:                case 2: /* point */
                    286:                        x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
1.5       noro      287:                        draw_point(display,can,x,y,color);
                    288:                        MKRVECT2(vect,x,y); MKNODE(n,vect,can->history); can->history = n;
                    289:                        break;
                    290:                case 3: /* circle */
                    291:                        x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
                    292:                        r = (int)ToReal((Q)ARG2(obj));
                    293:                        MKRVECT3(vect,x,y,r); MKNODE(n,vect,can->history); can->history = n;
1.4       noro      294:                        break;
                    295:                case 4: /* line */
                    296:                        x = (int)ToReal((Q)ARG0(obj)); y = (int)ToReal((Q)ARG1(obj));
                    297:                        u = (int)ToReal((Q)ARG2(obj)); v = (int)ToReal((Q)ARG3(obj));
1.5       noro      298:                        draw_line(display,can,x,y,u,v,color);
1.4       noro      299:                        MKRVECT4(vect,x,y,u,v); MKNODE(n,vect,can->history); can->history = n;
                    300:                        break;
                    301:                default:
1.5       noro      302:                        set_lasterror("draw_obj : invalid request");
1.4       noro      303:                        return -1;
                    304:        }
                    305:        return 0;
                    306: }
                    307:
                    308: int clear_canvas(NODE arg)
                    309: {
                    310:        int index;
                    311:        struct canvas *can;
                    312:
                    313:        index = QTOS((Q)ARG0(arg));
                    314:        can = canvas[index];
                    315:        if ( !can || !can->window )
                    316:                return -1;
                    317:        clear_pixmap(can);
                    318:        copy_to_canvas(can);
                    319:        /* clear the history */
                    320:        can->history = 0;
1.1       noro      321: }
                    322:
                    323: #define RealtoDbl(r) ((r)?BDY(r):0.0)
                    324:
                    325: int arrayplot(NODE arg)
                    326: {
                    327:        int id,ix,w,h;
                    328:        VECT array;
                    329:        LIST xrange,wsize;
                    330:        char *wname;
                    331:        NODE n;
                    332:        Q ret;
                    333:        double ymax,ymin,dy,xstep;
                    334:        Real *tab;
                    335:        struct canvas *can;
                    336:        POINT *pa;
                    337:
                    338:        array = (VECT)ARG0(arg);
                    339:        xrange = (LIST)ARG1(arg);
                    340:        can = canvas[id = search_canvas()];
                    341:        n = BDY(xrange); can->vx = VR((P)BDY(n)); n = NEXT(n);
                    342:        can->qxmin = (Q)BDY(n); n = NEXT(n); can->qxmax = (Q)BDY(n);
                    343:        can->xmin = ToReal(can->qxmin); can->xmax = ToReal(can->qxmax);
                    344:        if ( !wsize ) {
                    345:                can->width = DEFAULTWIDTH; can->height = DEFAULTHEIGHT;
                    346:        } else {
                    347:                can->width = QTOS((Q)BDY(BDY(wsize)));
                    348:                can->height = QTOS((Q)BDY(NEXT(BDY(wsize))));
                    349:        }
                    350:        can->wname = wname; can->formula = 0; can->mode = MODE_PLOT;
                    351:        create_canvas(can);
                    352:        w = array->len;
                    353:        h = can->height;
                    354:        tab = (Real *)BDY(array);
                    355:        if ( can->ymax == can->ymin ) {
                    356:                for ( ymax = ymin = RealtoDbl(tab[0]), ix = 1; ix < w; ix++ ) {
                    357:                        if ( RealtoDbl(tab[ix]) > ymax )
                    358:                                ymax = RealtoDbl(tab[ix]);
                    359:                        if ( RealtoDbl(tab[ix]) < ymin )
                    360:                                ymin = RealtoDbl(tab[ix]);
                    361:                }
                    362:                can->ymax = ymax; can->ymin = ymin;
                    363:        } else {
                    364:                ymax = can->ymax; ymin = can->ymin;
                    365:        }
                    366:        dy = ymax-ymin;
                    367:        can->pa = (struct pa *)MALLOC(sizeof(struct pa));
                    368:        can->pa[0].length = w;
                    369:        can->pa[0].pos = pa = (POINT *)MALLOC(w*sizeof(POINT));
                    370:        xstep = (double)can->width/(double)(w-1);
                    371:        for ( ix = 0; ix < w; ix++ ) {
                    372: #ifndef MAXSHORT
                    373: #define MAXSHORT ((short)0x7fff)
                    374: #endif
                    375:                double t;
                    376:
                    377:                pa[ix].x = (int)(ix*xstep);
                    378:                t = (h - 1)*(ymax - RealtoDbl(tab[ix]))/dy;
                    379:                if ( t > MAXSHORT )
                    380:                        pa[ix].y = MAXSHORT;
                    381:                else if ( t < -MAXSHORT )
                    382:                        pa[ix].y = -MAXSHORT;
                    383:                else
                    384:                        pa[ix].y = t;
                    385:        }
                    386:        plot_print(display,can);
                    387:        copy_to_canvas(can);
                    388:        return id;
                    389: }
                    390:
                    391: ifplot_resize(can,spos,epos)
                    392: struct canvas *can;
                    393: POINT spos,epos;
                    394: {
                    395:        struct canvas *ncan;
                    396:        struct canvas fakecan;
                    397:        Q dx,dy,dx2,dy2,xmin,xmax,ymin,ymax,xmid,ymid;
                    398:        Q sx,sy,ex,ey,cw,ch,ten,two;
                    399:        Q s,t;
                    400:        int new;
                    401:        int w,h,m;
                    402:        Q ret;
                    403:
                    404:        if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
                    405:                if ( can->precise && !can->wide ) {
                    406:                        fakecan = *can; ncan = &fakecan;
                    407:                } else {
                    408:                        new = search_canvas(); ncan = canvas[new];
                    409:                }
                    410:                ncan->mode = can->mode;
                    411:                ncan->zmin = can->zmin; ncan->zmax = can->zmax;
                    412:                ncan->nzstep = can->nzstep;
                    413:                ncan->wname = can->wname;
                    414:                ncan->vx = can->vx; ncan->vy = can->vy;
                    415:                ncan->formula = can->formula;
                    416:                w = XC(epos)-XC(spos);
                    417:                h = YC(epos)-YC(spos);
                    418:                m = MAX(can->width,can->height);
                    419:                if ( can->precise ) {
                    420:                        ncan->width = w; ncan->height = h;
                    421:                } else if ( w > h ) {
                    422:                        ncan->width = m; ncan->height = m * h/w;
                    423:                } else {
                    424:                        ncan->width = m * w/h; ncan->height = m;
                    425:                }
                    426:                if ( can->wide ) {
                    427:                        STOQ(10,ten); STOQ(2,two);
                    428:                        subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
                    429:                        subq(can->qymax,can->qymin,&t); mulq(t,ten,&dy);
                    430:                        addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
                    431:                        addq(can->qymax,can->qymin,&t); divq(t,two,&ymid);
                    432:                        divq(dx,two,&dx2); divq(dy,two,&dy2);
                    433:                        subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
                    434:                        subq(ymid,dy2,&ymin); addq(ymid,dy2,&ymax);
                    435:                } else {
                    436:                        subq(can->qxmax,can->qxmin,&dx); subq(can->qymax,can->qymin,&dy);
                    437:                        xmin = can->qxmin; xmax = can->qxmax;
                    438:                        ymin = can->qymin; ymax = can->qymax;
                    439:                }
                    440:                STOQ(XC(spos),sx); STOQ(YC(spos),sy); STOQ(XC(epos),ex); STOQ(YC(epos),ey);
                    441:                STOQ(can->width,cw); STOQ(can->height,ch);
                    442:                mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
                    443:                mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
                    444:                mulq(ey,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymin);
                    445:                mulq(sy,dy,&t); divq(t,ch,&s); subq(ymax,s,&ncan->qymax);
                    446:                ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
                    447:                ncan->ymin = ToReal(ncan->qymin); ncan->ymax = ToReal(ncan->qymax);
                    448:                if ( can->precise && !can->wide ) {
                    449:                        current_can = can;
                    450:                        alloc_pixmap(ncan);
1.4       noro      451: #if defined(VISUAL)
                    452:                        ncan->real_can = can;
                    453: #endif
1.1       noro      454:                        qifplotmain(ncan);
                    455:                        copy_subimage(ncan,can,spos);
                    456:                        copy_to_canvas(can);
                    457:                } else {
                    458:                        create_canvas(ncan);
                    459:                        if ( can->precise )
                    460:                                qifplotmain(ncan);
                    461:                        else
                    462:                                ifplotmain(ncan);
                    463:                        copy_to_canvas(ncan);
                    464:                }
                    465:        }
                    466: }
                    467:
                    468: plot_resize(can,spos,epos)
                    469: struct canvas *can;
                    470: POINT spos,epos;
                    471: {
                    472:        struct canvas *ncan;
                    473:        Q dx,dx2,xmin,xmax,xmid;
                    474:        double dy,dy2,ymin,ymax,ymid;
                    475:        Q sx,ex,cw,ten,two;
                    476:        double sy,ey;
                    477:        Q s,t;
                    478:        int new;
                    479:        int w,h,m;
                    480:
                    481:        if ( XC(spos) < XC(epos) && YC(spos) < YC(epos) ) {
                    482:                new = search_canvas(); ncan = canvas[new];
                    483:                ncan->mode = can->mode;
                    484:                ncan->zmin = can->zmin; ncan->zmax = can->zmax;
                    485:                ncan->nzstep = can->nzstep;
                    486:                ncan->wname = can->wname;
                    487:                ncan->vx = can->vx; ncan->vy = can->vy;
                    488:                ncan->formula = can->formula;
                    489:                w = XC(epos)-XC(spos);
                    490:                h = YC(epos)-YC(spos);
                    491:                m = MAX(can->width,can->height);
                    492:                if ( w > h ) {
                    493:                        ncan->width = m; ncan->height = m * h/w;
                    494:                } else {
                    495:                        ncan->width = m * w/h; ncan->height = m;
                    496:                }
                    497:                if ( can->wide ) {
                    498:                        STOQ(10,ten); STOQ(2,two);
                    499:                        subq(can->qxmax,can->qxmin,&t); mulq(t,ten,&dx);
                    500:                        addq(can->qxmax,can->qxmin,&t); divq(t,two,&xmid);
                    501:                        divq(dx,two,&dx2); subq(xmid,dx2,&xmin); addq(xmid,dx2,&xmax);
                    502:
                    503:                        dy = (can->ymax-can->ymin)*10;
                    504:                        ymid = (can->ymax+can->ymin)/2;
                    505:                        ymin = ymid-dy/2; ymax = ymid+dy/2;
                    506:                } else {
                    507:                        subq(can->qxmax,can->qxmin,&dx);
                    508:                        xmin = can->qxmin; xmax = can->qxmax;
                    509:
                    510:                        dy = can->ymax-can->ymin;
                    511:                        ymin = can->ymin; ymax = can->ymax;
                    512:                }
                    513:                STOQ(XC(spos),sx); STOQ(XC(epos),ex); STOQ(can->width,cw);
                    514:                mulq(sx,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmin);
                    515:                mulq(ex,dx,&t); divq(t,cw,&s); addq(xmin,s,&ncan->qxmax);
                    516:                ncan->xmin = ToReal(ncan->qxmin); ncan->xmax = ToReal(ncan->qxmax);
                    517:
                    518:                ncan->ymin = ymax-YC(epos)*dy/can->height;
                    519:                ncan->ymax = ymax-YC(spos)*dy/can->height;
                    520:
                    521:                create_canvas(ncan);
                    522:                plotcalc(ncan);
                    523:                plot_print(display,ncan);
                    524:                copy_to_canvas(ncan);
                    525:        }
                    526: }
                    527:
                    528: ifplotmain(can)
                    529: struct canvas *can;
                    530: {
                    531:        int width,height;
                    532:        double **tabe,*tabeb;
                    533:        int i;
                    534:
                    535:        width = can->width; height = can->height;
                    536:        tabe = (double **)ALLOCA(width*sizeof(double *));
                    537:        for ( i = 0; i < width; i++ )
                    538:                tabe[i] = (double *)ALLOCA(height*sizeof(double));
                    539:        define_cursor(can->window,runningcur);
                    540:        set_busy(can); set_selection();
1.6     ! noro      541:        calc(tabe,can,0); if_print(display,tabe,can);
1.1       noro      542:        reset_selection(); reset_busy(can);
                    543:        define_cursor(can->window,normalcur);
                    544: }
                    545:
                    546: qifplotmain(can)
                    547: struct canvas *can;
                    548: {
                    549:        int width,height;
                    550:        char **tabe,*tabeb;
                    551:        int i;
                    552:
                    553:        width = can->width; height = can->height;
                    554:        tabe = (char **)ALLOCA(width*sizeof(char *)+width*height*sizeof(char));
                    555:        bzero(tabe,width*sizeof(char *)+width*height*sizeof(char));
                    556:        for ( i = 0, tabeb = (char *)(tabe+width); i < width; i++ )
                    557:                tabe[i] = tabeb + height*i;
                    558:        define_cursor(can->window,runningcur);
                    559:        set_busy(can); set_selection();
                    560:        qcalc(tabe,can); qif_print(display,tabe,can);
                    561:        reset_selection(); reset_busy(can);
                    562:        define_cursor(can->window,normalcur);
                    563: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>