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

Annotation of OpenXM_contrib2/asir2000/plot/plotp.c, Revision 1.1.1.1

1.1       noro        1: /* $OpenXM: OpenXM/src/asir99/plot/plotp.c,v 1.1.1.1 1999/11/10 08:12:34 noro Exp $ */
                      2: #include "ca.h"
                      3: #include "parse.h"
                      4: #include "ox.h"
                      5: #include "ifplot.h"
                      6:
                      7: #if defined(sun) && !defined(__svr4__)
                      8: #define EXP10(a) exp10(a)
                      9: #else
                     10: #define EXP10(a) pow(10.0,a)
                     11: #endif
                     12:
                     13: if_print(display,tab,can)
                     14: DISPLAY *display;
                     15: double **tab;
                     16: struct canvas *can;
                     17: {
                     18:        int ix,iy,width,height;
                     19:        double *px,*px1,*px2;
                     20:        DRAWABLE pix;
                     21:
                     22:        if ( can->mode == MODE_CONPLOT ) {
                     23:                con_print(display,tab,can); return;
                     24:        }
                     25:        flush();
                     26:        width = can->width; height = can->height; pix = can->pix;
                     27:        for( ix=0; ix<width-1; ix++ )
                     28:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                     29:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                     30:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                     31:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                     32:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                     33:                                count_and_flush();
                     34:                        }
                     35:        flush();
                     36: }
                     37:
                     38: con_print(display,tab,can)
                     39: DISPLAY *display;
                     40: double **tab;
                     41: struct canvas *can;
                     42: {
                     43:        int ix,iy,iz,width,height,pas,pai,len;
                     44:        double zstep,z;
                     45:        double *px,*px1,*px2;
                     46:        DRAWABLE pix;
                     47:        POINT *pa,*pa1;
                     48:        struct pa *parray;
                     49:
                     50:
                     51:        width = can->width; height = can->height; pix = can->pix;
                     52:        zstep = (can->zmax-can->zmin)/can->nzstep;
                     53:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                     54:        pas = width;
                     55:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                     56:        initmarker(can,"Drawing...");
                     57:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                     58:                marker(can,DIR_Z,iz);
                     59:                pai = 0;
                     60:                for( ix=0; ix<width-1; ix++ )
                     61:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                     62:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                     63:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                     64:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                     65:                                        if ( pai == pas ) {
                     66:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                     67:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                     68:                                                pas += pas;
                     69:                                        }
                     70:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                     71:                                }
                     72:                can->pa[iz].length = pai;
                     73:                if ( pai ) {
                     74:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                     75:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                     76:                        can->pa[iz].pos = pa1;
                     77:                }
                     78:        }
                     79:        flush();
                     80:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                     81:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                     82:                        DRAWPOINT(display,pix,drawGC,XC(pa[ix]),YC(pa[ix]));
                     83:                        count_and_flush();
                     84:                }
                     85:        flush();
                     86: }
                     87:
                     88: qif_print(display,tab,can)
                     89: DISPLAY *display;
                     90: char **tab;
                     91: struct canvas *can;
                     92: {
                     93:        int ix,iy,width,height;
                     94:        char *px;
                     95:        DRAWABLE pix;
                     96:
                     97:        flush();
                     98:        width = can->width; height = can->height; pix = can->pix;
                     99:        for( ix = 0; ix < width; ix++ )
                    100:                for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                    101:                        if ( *px ) {
                    102:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                    103:                                count_and_flush();
                    104:                        }
                    105:        flush();
                    106: }
                    107:
                    108: plot_print(display,can)
                    109: DISPLAY *display;
                    110: struct canvas *can;
                    111: {
                    112:        int len,i;
                    113:        POINT *pa;
                    114:
                    115:        XDrawLines(display,can->pix,drawGC,
                    116:                can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
                    117:        XFlush(display);
                    118: }
                    119:
                    120: #define D 5
                    121:
                    122: pline(display,can,d)
                    123: DISPLAY *display;
                    124: struct canvas *can;
                    125: DRAWABLE d;
                    126: {
                    127:        double w,w1,k,e,n;
                    128:        int x0,y0,x,y,xadj,yadj;
                    129:        char buf[BUFSIZ];
                    130:        double adjust_scale();
                    131:
                    132:        if ( can->noaxis )
                    133:                return;
                    134:
                    135:        xadj = yadj = 0;
                    136:        if ( (can->xmin < 0) && (can->xmax > 0) ) {
                    137:                x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin)));
                    138:                DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
                    139:        } else if ( can->xmin >= 0 )
                    140:                x0 = 0;
                    141:        else
                    142:                x0 = can->width-1-D;
                    143:        if ( (can->ymin < 0) && (can->ymax > 0) ) {
                    144:                y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin)));
                    145:                DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
                    146:        } else if ( can->ymin >= 0 )
                    147:                y0 = can->height-1;
                    148:        else
                    149:                y0 = D;
                    150:        w = can->xmax-can->xmin;
                    151:        w1 = w * DEFAULTWIDTH/can->width;
                    152:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    153:        for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
                    154:                x = (int)can->width*(n*e-can->xmin)/w;
                    155:                DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                    156:                sprintf(buf,"%g",n*e);
                    157:                DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf));
                    158:        }
                    159:        w = can->ymax-can->ymin;
                    160:        w1 = w * DEFAULTHEIGHT/can->height;
                    161:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    162:        for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
                    163:                y = (int)can->height*(1-(n*e-can->ymin)/w);
                    164:                DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                    165:                sprintf(buf,"%g",n*e);
                    166:                if ( can->xmax <= 0 )
                    167:                        xadj = TEXTWIDTH(sffs,buf,strlen(buf));
                    168:                DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf));
                    169:        }
                    170: }
                    171:
                    172: double adjust_scale(e,w)
                    173: double e,w;
                    174: {
                    175:        switch ( (int)floor(w/e) ) {
                    176:                case 1:
                    177:                        return e/4; break;
                    178:                case 2: case 3:
                    179:                        return e/2; break;
                    180:                case 4: case 5: case 6: case 7:
                    181:                        return e; break;
                    182:                        break;
                    183:                case 8: case 9: case 10: default:
                    184:                        return 2*e; break;
                    185:        }
                    186: }
                    187:
                    188: initmarker(can,message)
                    189: struct canvas *can;
                    190: char *message;
                    191: {
                    192:        XawScrollbarSetThumb(can->xdone,0.0,0.0);
                    193:        XawScrollbarSetThumb(can->ydone,1.0,0.0);
                    194:        XFlush(display);
                    195: }
                    196:
                    197: marker(can,dir,p)
                    198: struct canvas *can;
                    199: int dir,p;
                    200: {
                    201:        if ( dir == DIR_X ) {
                    202:                XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
                    203:                count_and_flush();
                    204:        } else if ( dir == DIR_Y ) {
                    205:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
                    206:                count_and_flush();
                    207:        } else {
                    208:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
                    209:                flush();
                    210:        }
                    211: }
                    212:
                    213: define_cursor(w,cur)
                    214: WINDOW w;
                    215: CURSOR cur;
                    216: {
                    217:        XDefineCursor(display,w,cur); flush();
                    218: }
                    219:
                    220: static int flush_count;
                    221: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
                    222: #define MAX_COUNT 64
                    223: #else
                    224: #define MAX_COUNT 32
                    225: #endif
                    226:
                    227: count_and_flush() {
                    228:        if ( ++flush_count == MAX_COUNT )
                    229:                flush();
                    230: }
                    231:
                    232: flush() {
                    233:        flush_count = 0;
                    234:        XFlush(display);
                    235: }

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