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

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
        !            26:  * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification
        !            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:  *
        !            48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.2 2000/03/07 01:32:44 noro Exp $
        !            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:
                     62: if_print(display,tab,can)
                     63: DISPLAY *display;
                     64: double **tab;
                     65: struct canvas *can;
                     66: {
                     67:        int ix,iy,width,height;
                     68:        double *px,*px1,*px2;
                     69:        DRAWABLE pix;
                     70:
                     71:        if ( can->mode == MODE_CONPLOT ) {
                     72:                con_print(display,tab,can); return;
                     73:        }
                     74:        flush();
                     75:        width = can->width; height = can->height; pix = can->pix;
                     76:        for( ix=0; ix<width-1; ix++ )
                     77:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                     78:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                     79:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                     80:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                     81:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                     82:                                count_and_flush();
                     83:                        }
                     84:        flush();
                     85: }
                     86:
                     87: con_print(display,tab,can)
                     88: DISPLAY *display;
                     89: double **tab;
                     90: struct canvas *can;
                     91: {
                     92:        int ix,iy,iz,width,height,pas,pai,len;
                     93:        double zstep,z;
                     94:        double *px,*px1,*px2;
                     95:        DRAWABLE pix;
                     96:        POINT *pa,*pa1;
                     97:        struct pa *parray;
                     98:
                     99:
                    100:        width = can->width; height = can->height; pix = can->pix;
                    101:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    102:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    103:        pas = width;
                    104:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    105:        initmarker(can,"Drawing...");
                    106:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    107:                marker(can,DIR_Z,iz);
                    108:                pai = 0;
                    109:                for( ix=0; ix<width-1; ix++ )
                    110:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    111:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    112:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    113:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    114:                                        if ( pai == pas ) {
                    115:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    116:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    117:                                                pas += pas;
                    118:                                        }
                    119:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    120:                                }
                    121:                can->pa[iz].length = pai;
                    122:                if ( pai ) {
                    123:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    124:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    125:                        can->pa[iz].pos = pa1;
                    126:                }
                    127:        }
                    128:        flush();
                    129:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    130:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                    131:                        DRAWPOINT(display,pix,drawGC,XC(pa[ix]),YC(pa[ix]));
                    132:                        count_and_flush();
                    133:                }
                    134:        flush();
                    135: }
                    136:
                    137: qif_print(display,tab,can)
                    138: DISPLAY *display;
                    139: char **tab;
                    140: struct canvas *can;
                    141: {
                    142:        int ix,iy,width,height;
                    143:        char *px;
                    144:        DRAWABLE pix;
                    145:
                    146:        flush();
                    147:        width = can->width; height = can->height; pix = can->pix;
                    148:        for( ix = 0; ix < width; ix++ )
                    149:                for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                    150:                        if ( *px ) {
                    151:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                    152:                                count_and_flush();
                    153:                        }
                    154:        flush();
                    155: }
                    156:
                    157: plot_print(display,can)
                    158: DISPLAY *display;
                    159: struct canvas *can;
                    160: {
                    161:        int len,i;
                    162:        POINT *pa;
                    163:
                    164:        XDrawLines(display,can->pix,drawGC,
                    165:                can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
                    166:        XFlush(display);
                    167: }
                    168:
                    169: #define D 5
                    170:
                    171: pline(display,can,d)
                    172: DISPLAY *display;
                    173: struct canvas *can;
                    174: DRAWABLE d;
                    175: {
                    176:        double w,w1,k,e,n;
                    177:        int x0,y0,x,y,xadj,yadj;
                    178:        char buf[BUFSIZ];
                    179:        double adjust_scale();
                    180:
                    181:        if ( can->noaxis )
                    182:                return;
                    183:
                    184:        xadj = yadj = 0;
                    185:        if ( (can->xmin < 0) && (can->xmax > 0) ) {
                    186:                x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin)));
                    187:                DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
                    188:        } else if ( can->xmin >= 0 )
                    189:                x0 = 0;
                    190:        else
                    191:                x0 = can->width-1-D;
                    192:        if ( (can->ymin < 0) && (can->ymax > 0) ) {
                    193:                y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin)));
                    194:                DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
                    195:        } else if ( can->ymin >= 0 )
                    196:                y0 = can->height-1;
                    197:        else
                    198:                y0 = D;
                    199:        w = can->xmax-can->xmin;
                    200:        w1 = w * DEFAULTWIDTH/can->width;
                    201:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    202:        for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
                    203:                x = (int)can->width*(n*e-can->xmin)/w;
                    204:                DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                    205:                sprintf(buf,"%g",n*e);
                    206:                DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf));
                    207:        }
                    208:        w = can->ymax-can->ymin;
                    209:        w1 = w * DEFAULTHEIGHT/can->height;
                    210:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    211:        for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
                    212:                y = (int)can->height*(1-(n*e-can->ymin)/w);
                    213:                DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                    214:                sprintf(buf,"%g",n*e);
                    215:                if ( can->xmax <= 0 )
                    216:                        xadj = TEXTWIDTH(sffs,buf,strlen(buf));
                    217:                DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf));
                    218:        }
                    219: }
                    220:
                    221: double adjust_scale(e,w)
                    222: double e,w;
                    223: {
                    224:        switch ( (int)floor(w/e) ) {
                    225:                case 1:
                    226:                        return e/4; break;
                    227:                case 2: case 3:
                    228:                        return e/2; break;
                    229:                case 4: case 5: case 6: case 7:
                    230:                        return e; break;
                    231:                        break;
                    232:                case 8: case 9: case 10: default:
                    233:                        return 2*e; break;
                    234:        }
                    235: }
                    236:
                    237: initmarker(can,message)
                    238: struct canvas *can;
                    239: char *message;
                    240: {
                    241:        XawScrollbarSetThumb(can->xdone,0.0,0.0);
                    242:        XawScrollbarSetThumb(can->ydone,1.0,0.0);
                    243:        XFlush(display);
                    244: }
                    245:
                    246: marker(can,dir,p)
                    247: struct canvas *can;
                    248: int dir,p;
                    249: {
                    250:        if ( dir == DIR_X ) {
                    251:                XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
                    252:                count_and_flush();
                    253:        } else if ( dir == DIR_Y ) {
                    254:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
                    255:                count_and_flush();
                    256:        } else {
                    257:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
                    258:                flush();
                    259:        }
                    260: }
                    261:
                    262: define_cursor(w,cur)
                    263: WINDOW w;
                    264: CURSOR cur;
                    265: {
                    266:        XDefineCursor(display,w,cur); flush();
                    267: }
                    268:
                    269: static int flush_count;
                    270: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
                    271: #define MAX_COUNT 64
                    272: #else
                    273: #define MAX_COUNT 32
                    274: #endif
                    275:
                    276: count_and_flush() {
                    277:        if ( ++flush_count == MAX_COUNT )
                    278:                flush();
                    279: }
                    280:
                    281: flush() {
                    282:        flush_count = 0;
                    283:        XFlush(display);
                    284: }

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