[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.5

1.3       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.4       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3       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.5     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.4 2000/08/22 05:04:33 noro Exp $
1.3       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "ox.h"
                     53: #include "ifplot.h"
1.2       noro       54: #include <math.h>
1.1       noro       55:
                     56: #if defined(sun) && !defined(__svr4__)
                     57: #define EXP10(a) exp10(a)
                     58: #else
                     59: #define EXP10(a) pow(10.0,a)
                     60: #endif
                     61:
1.5     ! noro       62: #if defined(VISUAL)
        !            63: static POINT oldpos;
        !            64: #endif
        !            65:
1.1       noro       66: if_print(display,tab,can)
                     67: DISPLAY *display;
                     68: double **tab;
                     69: struct canvas *can;
                     70: {
                     71:        int ix,iy,width,height;
                     72:        double *px,*px1,*px2;
                     73:        DRAWABLE pix;
                     74:
                     75:        if ( can->mode == MODE_CONPLOT ) {
                     76:                con_print(display,tab,can); return;
                     77:        }
                     78:        flush();
                     79:        width = can->width; height = can->height; pix = can->pix;
                     80:        for( ix=0; ix<width-1; ix++ )
                     81:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                     82:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                     83:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                     84:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                     85:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                     86:                                count_and_flush();
                     87:                        }
                     88:        flush();
                     89: }
                     90:
                     91: con_print(display,tab,can)
                     92: DISPLAY *display;
                     93: double **tab;
                     94: struct canvas *can;
                     95: {
                     96:        int ix,iy,iz,width,height,pas,pai,len;
                     97:        double zstep,z;
                     98:        double *px,*px1,*px2;
                     99:        DRAWABLE pix;
                    100:        POINT *pa,*pa1;
                    101:        struct pa *parray;
                    102:
                    103:
                    104:        width = can->width; height = can->height; pix = can->pix;
                    105:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    106:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    107:        pas = width;
                    108:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    109:        initmarker(can,"Drawing...");
                    110:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    111:                marker(can,DIR_Z,iz);
                    112:                pai = 0;
                    113:                for( ix=0; ix<width-1; ix++ )
                    114:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    115:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    116:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    117:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    118:                                        if ( pai == pas ) {
                    119:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    120:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    121:                                                pas += pas;
                    122:                                        }
                    123:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    124:                                }
                    125:                can->pa[iz].length = pai;
                    126:                if ( pai ) {
                    127:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    128:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    129:                        can->pa[iz].pos = pa1;
                    130:                }
                    131:        }
                    132:        flush();
                    133:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    134:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                    135:                        DRAWPOINT(display,pix,drawGC,XC(pa[ix]),YC(pa[ix]));
                    136:                        count_and_flush();
                    137:                }
                    138:        flush();
                    139: }
                    140:
                    141: qif_print(display,tab,can)
                    142: DISPLAY *display;
                    143: char **tab;
                    144: struct canvas *can;
                    145: {
                    146:        int ix,iy,width,height;
                    147:        char *px;
                    148:        DRAWABLE pix;
                    149:
                    150:        flush();
                    151:        width = can->width; height = can->height; pix = can->pix;
                    152:        for( ix = 0; ix < width; ix++ )
                    153:                for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                    154:                        if ( *px ) {
                    155:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                    156:                                count_and_flush();
                    157:                        }
                    158:        flush();
                    159: }
                    160:
                    161: plot_print(display,can)
                    162: DISPLAY *display;
                    163: struct canvas *can;
                    164: {
                    165:        int len,i;
                    166:        POINT *pa;
1.5     ! noro      167:
        !           168: #if defined(VISUAL)
        !           169:        len = can->pa[0].length;
        !           170:        pa = can->pa[0].pos;
        !           171:        for ( i = 0; i < len-1; i++ ) {
        !           172:                DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
        !           173:        }
        !           174: #else
1.1       noro      175:        XDrawLines(display,can->pix,drawGC,
                    176:                can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
                    177:        XFlush(display);
1.5     ! noro      178: #endif
        !           179: }
        !           180:
        !           181: draw_point(display,can,x,y)
        !           182: DISPLAY *display;
        !           183: struct canvas *can;
        !           184: int x,y;
        !           185: {
        !           186: #if defined(VISUAL)
        !           187:        HDC dc;
        !           188:
        !           189:        y = can->height-y;
        !           190:        DRAWPOINT(display,can->pix,drawGC,x,y);
        !           191:        dc = GetDC(can->hwnd);
        !           192:        DRAWPOINT(display,dc,drawGC,x,y);
        !           193:        ReleaseDC(can->hwnd,dc);
        !           194: #else
        !           195:        y = can->height-y;
        !           196:        DRAWPOINT(display,can->pix,drawGC,x,y);
        !           197:        DRAWPOINT(display,can->window,drawGC,x,y);
        !           198:        XFlush(display);
        !           199: #endif
        !           200: }
        !           201:
        !           202: draw_line(display,can,x,y,u,v)
        !           203: DISPLAY *display;
        !           204: struct canvas *can;
        !           205: int x,y,u,v;
        !           206: {
        !           207: #if defined(VISUAL)
        !           208:        HDC dc;
        !           209:
        !           210:        y = can->height-y;
        !           211:        v = can->height-v;
        !           212:        DRAWLINE(display,can->pix,drawGC,x,y,u,v);
        !           213:        dc = GetDC(can->hwnd);
        !           214:        DRAWLINE(display,dc,drawGC,x,y,u,v);
        !           215:        ReleaseDC(can->hwnd,dc);
        !           216: #else
        !           217:        y = can->height-y;
        !           218:        v = can->height-v;
        !           219:        DRAWLINE(display,can->pix,drawGC,x,y,u,v);
        !           220:        DRAWLINE(display,can->window,drawGC,x,y,u,v);
        !           221:        XFlush(display);
        !           222: #endif
1.1       noro      223: }
                    224:
                    225: #define D 5
                    226:
                    227: pline(display,can,d)
                    228: DISPLAY *display;
                    229: struct canvas *can;
                    230: DRAWABLE d;
                    231: {
                    232:        double w,w1,k,e,n;
                    233:        int x0,y0,x,y,xadj,yadj;
                    234:        char buf[BUFSIZ];
                    235:        double adjust_scale();
                    236:
1.5     ! noro      237:        /* XXX : should be cleaned up */
        !           238:        if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
        !           239:                return;
        !           240:        if ( can->mode == MODE_INTERACTIVE )
1.1       noro      241:                return;
                    242:
                    243:        xadj = yadj = 0;
                    244:        if ( (can->xmin < 0) && (can->xmax > 0) ) {
                    245:                x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin)));
                    246:                DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
                    247:        } else if ( can->xmin >= 0 )
                    248:                x0 = 0;
                    249:        else
                    250:                x0 = can->width-1-D;
                    251:        if ( (can->ymin < 0) && (can->ymax > 0) ) {
                    252:                y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin)));
                    253:                DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
                    254:        } else if ( can->ymin >= 0 )
                    255:                y0 = can->height-1;
                    256:        else
                    257:                y0 = D;
                    258:        w = can->xmax-can->xmin;
                    259:        w1 = w * DEFAULTWIDTH/can->width;
                    260:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    261:        for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
                    262:                x = (int)can->width*(n*e-can->xmin)/w;
                    263:                DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                    264:                sprintf(buf,"%g",n*e);
                    265:                DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf));
                    266:        }
                    267:        w = can->ymax-can->ymin;
                    268:        w1 = w * DEFAULTHEIGHT/can->height;
                    269:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
1.5     ! noro      270:        if ( w == 0 )
        !           271:                printf("afo");
1.1       noro      272:        for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
                    273:                y = (int)can->height*(1-(n*e-can->ymin)/w);
                    274:                DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                    275:                sprintf(buf,"%g",n*e);
                    276:                if ( can->xmax <= 0 )
                    277:                        xadj = TEXTWIDTH(sffs,buf,strlen(buf));
                    278:                DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf));
                    279:        }
                    280: }
                    281:
                    282: double adjust_scale(e,w)
                    283: double e,w;
                    284: {
                    285:        switch ( (int)floor(w/e) ) {
                    286:                case 1:
                    287:                        return e/4; break;
                    288:                case 2: case 3:
                    289:                        return e/2; break;
                    290:                case 4: case 5: case 6: case 7:
                    291:                        return e; break;
                    292:                        break;
                    293:                case 8: case 9: case 10: default:
                    294:                        return 2*e; break;
                    295:        }
                    296: }
                    297:
                    298: initmarker(can,message)
                    299: struct canvas *can;
                    300: char *message;
                    301: {
1.5     ! noro      302: #if defined(VISUAL)
        !           303:        can->real_can->percentage = 0;
        !           304:        can->real_can->prefix = message;
        !           305: #else
1.1       noro      306:        XawScrollbarSetThumb(can->xdone,0.0,0.0);
                    307:        XawScrollbarSetThumb(can->ydone,1.0,0.0);
                    308:        XFlush(display);
1.5     ! noro      309: #endif
1.1       noro      310: }
                    311:
                    312: marker(can,dir,p)
                    313: struct canvas *can;
                    314: int dir,p;
                    315: {
1.5     ! noro      316: #if defined(VISUAL)
        !           317:        if ( dir == DIR_X )
        !           318:                can->real_can->percentage = ceil((float)p/(float)can->real_can->width*100);
        !           319:        else if ( dir == DIR_Y )
        !           320:                can->real_can->percentage = ceil((float)p/(float)can->real_can->height*100);
        !           321:        else
        !           322:                can->real_can->percentage = ceil((float)p/(float)can->real_can->nzstep*100);
        !           323: #else
1.1       noro      324:        if ( dir == DIR_X ) {
                    325:                XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
                    326:                count_and_flush();
                    327:        } else if ( dir == DIR_Y ) {
                    328:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
                    329:                count_and_flush();
                    330:        } else {
                    331:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
                    332:                flush();
                    333:        }
1.5     ! noro      334: #endif
1.1       noro      335: }
                    336:
                    337: define_cursor(w,cur)
                    338: WINDOW w;
                    339: CURSOR cur;
                    340: {
1.5     ! noro      341: #if !defined(VISUAL)
1.1       noro      342:        XDefineCursor(display,w,cur); flush();
1.5     ! noro      343: #endif
1.1       noro      344: }
                    345:
                    346: static int flush_count;
                    347: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
                    348: #define MAX_COUNT 64
                    349: #else
                    350: #define MAX_COUNT 32
                    351: #endif
                    352:
                    353: count_and_flush() {
1.5     ! noro      354: #if !defined(VISUAL)
1.1       noro      355:        if ( ++flush_count == MAX_COUNT )
                    356:                flush();
1.5     ! noro      357: #endif
1.1       noro      358: }
                    359:
                    360: flush() {
1.5     ! noro      361: #if !defined(VISUAL)
1.1       noro      362:        flush_count = 0;
                    363:        XFlush(display);
1.5     ! noro      364: #endif
1.1       noro      365: }

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