Esempio n. 1
0
int
main( int argc, char *argv[] )
{
    PLFLT xmin0, xmax0, ymin0, ymax0, zxmin0, zxmax0, zymin0, zymax0;
    PLFLT xmin, xmax, ymin, ymax, zxmin, zxmax, zymin, zymax;
    PLFLT xmid, ymid, wx, wy;
    PLFLT mar0, aspect0, jx0, jy0, ori0;
    PLFLT mar, aspect, jx, jy, ori;
    PLINT win, level2, digmax, digits, compression1, compression2;
    PLFLT xp0, yp0;
    PLINT xleng0, yleng0, xoff0, yoff0;
    PLFLT xp1, yp1;
    PLINT xleng1, yleng1, xoff1, yoff1;
    PLFLT xp2, yp2;
    PLINT xleng2, yleng2, xoff2, yoff2;
    PLINT fam0, num0, bmax0;
    PLINT fam1, num1, bmax1;
    PLINT fam2, num2, bmax2;
    PLINT r0, g0, b0;
    PLFLT a0;
    PLINT r, g, b;
    PLFLT a;
    PLINT r1[] = { 0, 255 };
    PLINT g1[] = { 255, 0 };
    PLINT b1[] = { 0, 0 };
    PLFLT a1[] = { 1.0, 1.0 };
    int   status;
    char  fnam[256];

    // Parse and process command line arguments

    status = 0;

    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

    // Test setting / getting familying parameters before plinit
    // Save values set by plparseopts to be restored later.
    plgfam( &fam0, &num0, &bmax0 );
    fam1  = 0;
    num1  = 10;
    bmax1 = 1000;
    plsfam( fam1, num1, bmax1 );

    // Retrieve the same values?
    plgfam( &fam2, &num2, &bmax2 );
    printf( "family parameters: fam, num, bmax = %d %d %d\n", fam2, num2, bmax2 );
    if ( fam2 != fam1 || num2 != num1 || bmax2 != bmax1 )
    {
        fputs( "plgfam test failed\n", stderr );
        status = 1;
    }
    // Restore values set initially by plparseopts.
    plsfam( fam0, num0, bmax0 );

    // Test setting / getting page parameters before plinit
    // Save values set by plparseopts to be restored later.
    plgpage( &xp0, &yp0, &xleng0, &yleng0, &xoff0, &yoff0 );
    xp1    = 200.;
    yp1    = 200.;
    xleng1 = 400;
    yleng1 = 200;
    xoff1  = 10;
    yoff1  = 20;
    plspage( xp1, yp1, xleng1, yleng1, xoff1, yoff1 );

    // Retrieve the same values?
    plgpage( &xp2, &yp2, &xleng2, &yleng2, &xoff2, &yoff2 );
    printf( "page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d\n", xp2, yp2, xleng2, yleng2, xoff2, yoff2 );
    if ( xp2 != xp1 || yp2 != yp1 || xleng2 != xleng1 || yleng2 != yleng1 ||
         xoff2 != xoff1 || yoff2 != yoff1 )
    {
        fputs( "plgpage test failed\n", stderr );
        status = 1;
    }
    // Restore values set initially by plparseopts.
    plspage( xp0, yp0, xleng0, yleng0, xoff0, yoff0 );

    // Test setting / getting compression parameter across plinit.
    compression1 = 95;
    plscompression( compression1 );

    // Initialize plplot
    plinit();

    // Test if device initialization screwed around with the preset
    // compression parameter.
    plgcompression( &compression2 );
    printf( "Output various PLplot parameters\n" );
    printf( "compression parameter = %d\n", compression2 );
    if ( compression2 != compression1 )
    {
        fputs( "plgcompression test failed\n", stderr );
        status = 1;
    }


    // Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure
    // they work without any obvious error messages.
    plscolor( 1 );
    plscol0( 1, 255, 0, 0 );
    plscmap1( r1, g1, b1, 2 );
    plscmap1a( r1, g1, b1, a1, 2 );

    plglevel( &level2 );
    printf( "level parameter = %d\n", level2 );
    if ( level2 != 1 )
    {
        fputs( "plglevel test failed.\n", stderr );
        status = 1;
    }

    pladv( 0 );

    xmin0 = 0.01;
    xmax0 = 0.99;
    ymin0 = 0.02;
    ymax0 = 0.49;
    plvpor( xmin0, xmax0, ymin0, ymax0 );
    plgvpd( &xmin, &xmax, &ymin, &ymax );
    printf( "plvpor: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax );
    if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 )
    {
        fputs( "plgvpd test failed\n", stderr );
        status = 1;
    }
    xmid = 0.5 * ( xmin + xmax );
    ymid = 0.5 * ( ymin + ymax );

    xmin0 = 0.2;
    xmax0 = 0.3;
    ymin0 = 0.4;
    ymax0 = 0.5;
    plwind( xmin0, xmax0, ymin0, ymax0 );
    plgvpw( &xmin, &xmax, &ymin, &ymax );
    printf( "plwind: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax );
    if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 )
    {
        fputs( "plgvpw test failed\n", stderr );
        status = 1;
    }

    // Get world coordinates for middle of viewport
    plcalc_world( xmid, ymid, &wx, &wy, &win );
    printf( "world parameters: wx, wy, win = %f %f %d\n", wx, wy, win );
    if ( fabs( wx - 0.5 * ( xmin + xmax ) ) > 1.0E-5 || fabs( wy - 0.5 * ( ymin + ymax ) ) > 1.0E-5 )
    {
        fputs( "plcalc_world test failed\n", stderr );
        status = 1;
    }

    // Retrieve and print the name of the output file (if any).
    // This goes to stderr not stdout since it will vary between tests and
    // we want stdout to be identical for compare test.
    plgfnam( fnam );
    if ( fnam[0] == '\0' )
    {
        printf( "No output file name is set\n" );
    }
    else
    {
        printf( "Output file name read\n" );
    }
    fprintf( stderr, "Output file name is %s\n", fnam );

    // Set and get the number of digits used to display axis labels
    // Note digits is currently ignored in pls[xyz]ax and
    // therefore it does not make sense to test the returned
    // value
    plsxax( 3, 0 );
    plgxax( &digmax, &digits );
    printf( "x axis parameters: digmax, digits = %d %d\n", digmax, digits );
    if ( digmax != 3 )
    {
        fputs( "plgxax test failed\n", stderr );
        status = 1;
    }

    plsyax( 4, 0 );
    plgyax( &digmax, &digits );
    printf( "y axis parameters: digmax, digits = %d %d\n", digmax, digits );
    if ( digmax != 4 )
    {
        fputs( "plgyax test failed\n", stderr );
        status = 1;
    }

    plszax( 5, 0 );
    plgzax( &digmax, &digits );
    printf( "z axis parameters: digmax, digits = %d %d\n", digmax, digits );
    if ( digmax != 5 )
    {
        fputs( "plgzax test failed\n", stderr );
        status = 1;
    }

    mar0    = 0.05;
    aspect0 = PL_NOTSET;
    jx0     = 0.1;
    jy0     = 0.2;
    plsdidev( mar0, aspect0, jx0, jy0 );
    plgdidev( &mar, &aspect, &jx, &jy );
    printf( "device-space window parameters: mar, aspect, jx, jy = %f %f %f %f\n", mar, aspect, jx, jy );
    if ( mar != mar0 || jx != jx0 || jy != jy0 )
    {
        fputs( "plgdidev test failed\n", stderr );
        status = 1;
    }

    ori0 = 1.0;
    plsdiori( ori0 );
    plgdiori( &ori );
    printf( "ori parameter = %f\n", ori );
    if ( ori != ori0 )
    {
        fputs( "plgdiori test failed\n", stderr );
        status = 1;
    }

    xmin0 = 0.1;
    ymin0 = 0.2;
    xmax0 = 0.9;
    ymax0 = 0.8;
    plsdiplt( xmin0, ymin0, xmax0, ymax0 );
    plgdiplt( &xmin, &ymin, &xmax, &ymax );
    printf( "plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", xmin, ymin, xmax, ymax );
    if ( xmin != xmin0 || ymin != ymin0 || xmax != xmax0 || ymax != ymax0 )
    {
        fputs( "plgdiplt test failed\n", stderr );
        status = 1;
    }

    zxmin0 = 0.1;
    zymin0 = 0.1;
    zxmax0 = 0.9;
    zymax0 = 0.9;
    plsdiplz( zxmin0, zymin0, zxmax0, zymax0 );
    plgdiplt( &zxmin, &zymin, &zxmax, &zymax );
    printf( "zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", zxmin, zymin, zxmax, zymax );
    if ( fabs( zxmin - ( xmin + ( xmax - xmin ) * zxmin0 ) ) > 1.0E-5 ||
         fabs( zymin - ( ymin + ( ymax - ymin ) * zymin0 ) ) > 1.0E-5 ||
         fabs( zxmax - ( xmin + ( xmax - xmin ) * zxmax0 ) ) > 1.0E-5 ||
         fabs( zymax - ( ymin + ( ymax - ymin ) * zymax0 ) ) > 1.0E-5 )
    {
        fputs( "plsdiplz test failed\n", stderr );
        status = 1;
    }

    r0 = 10;
    g0 = 20;
    b0 = 30;
    plscolbg( r0, g0, b0 );
    plgcolbg( &r, &g, &b );
    printf( "background colour parameters: r, g, b = %d %d %d\n", r, g, b );
    if ( r != r0 || g != g0 || b != b0 )
    {
        fputs( "plgcolbg test failed\n", stderr );
        status = 1;
    }

    r0 = 20;
    g0 = 30;
    b0 = 40;
    a0 = 0.5;
    plscolbga( r0, g0, b0, a0 );
    plgcolbga( &r, &g, &b, &a );
    printf( "background/transparency colour parameters: r, g, b, a = %d %d %d %f\n", r, g, b, a );
    if ( r != r0 || g != g0 || b != b0 || a != a0 )
    {
        fputs( "plgcolbga test failed\n", stderr );
        status = 1;
    }

    plend();

    exit( status );
}
Esempio n. 2
0
void
c_plbin(PLINT nbin, PLFLT *x, PLFLT *y, PLINT flags)
{
    PLINT i;
    PLFLT xmin, xmax, vpwxmi, vpwxma, vpwymi, vpwyma;

    if (plsc->level < 3) {
	plabort("plbin: Please set up window first");
	return;
    }

    /* Check x[i] are in ascending order */

    for (i = 0; i < nbin - 1; i++) {
	if (x[i] >= x[i + 1]) {
	    plabort("plbin: Elements of x array must be increasing");
	    return;
	}
    }

    plgvpw(&vpwxmi, &vpwxma, &vpwymi, &vpwyma);
    if (!(flags & 1)) {
	for (i = 0; i < nbin - 1; i++) {
	    if (!(flags & 4) || (y[i] != vpwymi)) {
		pljoin(x[i], vpwymi, x[i], y[i]);
		pljoin(x[i], y[i], x[i + 1], y[i]);
		pljoin(x[i + 1], y[i], x[i + 1], vpwymi);
	    }
	}
	if (flags & 2) {
	    if (!(flags & 4) || (y[i] != vpwymi)) {
		int xm = x[i] + (x[i] - x[i-1]);
		pljoin(x[i], vpwymi, x[i], y[i]);
		pljoin(x[i], y[i], xm, y[i]);
		pljoin(xm, y[i], xm, vpwymi);
	    }
	} else {
	    if (x[i] < vpwxma) {
		if (!(flags & 4) || (y[i] != vpwymi)) {
		    pljoin(x[i], vpwymi, x[i], y[i]);
		    pljoin(x[i], y[i], vpwxma, y[i]);
		    pljoin(vpwxma, y[i], vpwxma, vpwymi);
		}
	    }
	}
    } else {
	if (nbin < 2)
	    return;
	if (flags & 2) {
	    xmin = MAX(vpwxmi, 0.5 * (3 * x[0] - x[1]));
	} else {
	    xmin = vpwxmi;
	}
	/* Vince fixed bug May 1998 */
	xmax = MAX(0.5 * (x[0] + x[1]), vpwxmi);
	if (xmin < xmax) {
	    pljoin(xmin, vpwymi, xmin, y[0]);
	    pljoin(xmin, y[0], xmax, y[0]);
	    pljoin(xmax, y[0], xmax, vpwymi);
	}
	for (i = 1; i < nbin - 1; i++) {
	    xmin = xmax;
	    xmax = MIN(0.5 * (x[i] + x[i + 1]), vpwxma);
	    if (!(flags & 4) || (y[i] != vpwymi)) {
		pljoin(xmin, vpwymi, xmin, y[i]);
		pljoin(xmin, y[i], xmax, y[i]);
		pljoin(xmax, y[i], xmax, vpwymi);
	    }
	}
	xmin = xmax;
	xmax = vpwxma;
	if (flags & 2) {
	    xmax = MIN(vpwxma, 0.5 * (3 * x[i] - x[i-1]));
	} else {
	    xmax = vpwxma;
	}
	if (xmin < xmax) {
	    if (!(flags & 4) || (y[i] != vpwymi)) {
		pljoin(xmin, vpwymi, xmin, y[i]);
		pljoin(xmin, y[i], xmax, y[i]);
		pljoin(xmax, y[i], xmax, vpwymi);
	    }
	}
    }
}
Esempio n. 3
0
static void
label_box(const char *xopt, PLFLT xtick1, const char *yopt, PLFLT ytick1)
{
    static char string[40];
    PLINT lfx, lix, llx, lmx, lnx, ltx;
    PLINT lfy, liy, lly, lmy, lny, lty, lvy;
    PLFLT vpwxmi, vpwxma, vpwymi, vpwyma;
    PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax;
    PLFLT pos, tn, tp, offset, height;

/* Set plot options from input */

    lfx = plP_stsearch(xopt, 'f');
    lix = plP_stsearch(xopt, 'i');
    llx = plP_stsearch(xopt, 'l');
    lmx = plP_stsearch(xopt, 'm');
    lnx = plP_stsearch(xopt, 'n');
    ltx = plP_stsearch(xopt, 't');

    lfy = plP_stsearch(yopt, 'f');
    liy = plP_stsearch(yopt, 'i');
    lly = plP_stsearch(yopt, 'l');
    lmy = plP_stsearch(yopt, 'm');
    lny = plP_stsearch(yopt, 'n');
    lty = plP_stsearch(yopt, 't');
    lvy = plP_stsearch(yopt, 'v');

    plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax);
/* n.b. large change; vpwxmi always numerically less than vpwxma, and
 * similarly for vpwymi */
    vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax;
    vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin;
    vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax;
    vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin;

/* Write horizontal label(s) */

    if ((lmx || lnx) && ltx) {
	PLINT xmode, xprec, xdigmax, xdigits, xscale;

	plgxax(&xdigmax, &xdigits);
	pldprec(vpwxmi, vpwxma, xtick1, lfx, &xmode, &xprec, xdigmax, &xscale);

	tp = xtick1 * (1. + floor(vpwxmi / xtick1));
	for (tn = tp; BETW(tn, vpwxmi, vpwxma); tn += xtick1) {
	    plform(tn, xscale, xprec, string, llx, lfx);
	    height = lix ? 1.75 : 1.5;
	    pos = (vpwxmax > vpwxmin)? 
	        (tn - vpwxmi) / (vpwxma - vpwxmi):
	        (vpwxma - tn) / (vpwxma - vpwxmi);
  	    if (lnx)
		plmtex("b", height, pos, 0.5, string);
	    if (lmx)
		plmtex("t", height, pos, 0.5, string);
	}
	xdigits = 2;
	plsxax(xdigmax, xdigits);

    /* Write separate exponential label if mode = 1. */

	if (!llx && xmode) {
	    pos = 1.0;
	    height = 3.2;
	    sprintf(string, "(x10#u%d#d)", (int) xscale);
	    if (lnx)
		plmtex("b", height, pos, 0.5, string);
	    if (lmx)
		plmtex("t", height, pos, 0.5, string);
	}
    }

/* Write vertical label(s) */

    if ((lmy || lny) && lty) {
	PLINT ymode, yprec, ydigmax, ydigits, yscale;

	plgyax(&ydigmax, &ydigits);
	pldprec(vpwymi, vpwyma, ytick1, lfy, &ymode, &yprec, ydigmax, &yscale);

	ydigits = 0;
	tp = ytick1 * (1. + floor(vpwymi / ytick1));
	for (tn = tp; BETW(tn, vpwymi, vpwyma); tn += ytick1) {
	    plform(tn, yscale, yprec, string, lly, lfy);
	    pos = (vpwymax > vpwymin)? 
	        (tn - vpwymi) / (vpwyma - vpwymi):
	        (vpwyma - tn) / (vpwyma - vpwymi);
	    if (lny) {
		if (lvy) {
		    height = liy ? 1.0 : 0.5;
		    plmtex("lv", height, pos, 1.0, string);
		} else {
		    height = liy ? 1.75 : 1.5;
		    plmtex("l", height, pos, 0.5, string);
		}
	    }
	    if (lmy) {
		if (lvy) {
		    height = liy ? 1.0 : 0.5;
		    plmtex("rv", height, pos, 0.0, string);
		} else {
		    height = liy ? 1.75 : 1.5;
		    plmtex("r", height, pos, 0.5, string);
		}
	    }
	    ydigits = MAX(ydigits, strlen(string));
	}
	if (!lvy)
	    ydigits = 2;

	plsyax(ydigmax, ydigits);

    /* Write separate exponential label if mode = 1. */

	if (!lly && ymode) {
	    sprintf(string, "(x10#u%d#d)", (int) yscale);
	    offset = 0.02;
	    height = 2.0;
	    if (lny) {
		pos = 0.0 - offset;
		plmtex("t", height, pos, 1.0, string);
	    }
	    if (lmy) {
		pos = 1.0 + offset;
		plmtex("t", height, pos, 0.0, string);
	    }
	}
    }
}
Esempio n. 4
0
void
c_plaxes(PLFLT x0, PLFLT y0,
	 const char *xopt, PLFLT xtick, PLINT nxsub,
	 const char *yopt, PLFLT ytick, PLINT nysub)
{
    PLINT lax, lbx, lcx, lgx, lix, llx, lsx, ltx;
    PLINT lay, lby, lcy, lgy, liy, lly, lsy, lty;
    PLINT xmajor, xminor, ymajor, yminor;
    PLINT i, i1x, i2x, i3x, i4x, i1y, i2y, i3y, i4y;
    PLINT nxsub1, nysub1;
    PLINT lxmin, lxmax, lymin, lymax;
    PLINT pxmin, pxmax, pymin, pymax;
    PLINT vppxmi, vppxma, vppymi, vppyma;
    PLFLT xtick1, ytick1, vpwxmi, vpwxma, vpwymi, vpwyma;
    PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax;
    PLFLT xp0, yp0, tn, tp, temp;

    if (plsc->level < 3) {
	plabort("plbox: Please set up window first");
	return;
    }

/* Open the clip limits to the subpage limits */

    plP_gclp(&lxmin, &lxmax, &lymin, &lymax);
    plP_gphy(&pxmin, &pxmax, &pymin, &pymax);
    plP_sclp(pxmin, pxmax, pymin, pymax);

    vppxmi = plsc->vppxmi;
    vppxma = plsc->vppxma;
    vppymi = plsc->vppymi;
    vppyma = plsc->vppyma;

/* Convert world coordinates to physical */

    xp0 = plP_wcpcx(x0);
    yp0 = plP_wcpcy(y0);

/* Set plot options from input */

    lax = plP_stsearch(xopt, 'a');
    lbx = plP_stsearch(xopt, 'b');
    lcx = plP_stsearch(xopt, 'c');
    lgx = plP_stsearch(xopt, 'g');
    lix = plP_stsearch(xopt, 'i');
    llx = plP_stsearch(xopt, 'l');
    lsx = plP_stsearch(xopt, 's');
    ltx = plP_stsearch(xopt, 't');

    lay = plP_stsearch(yopt, 'a');
    lby = plP_stsearch(yopt, 'b');
    lcy = plP_stsearch(yopt, 'c');
    lgy = plP_stsearch(yopt, 'g');
    liy = plP_stsearch(yopt, 'i');
    lly = plP_stsearch(yopt, 'l');
    lsy = plP_stsearch(yopt, 's');
    lty = plP_stsearch(yopt, 't');

/* Tick and subtick sizes in device coords */

    xmajor = MAX(ROUND(plsc->majht * plsc->ypmm), 1);
    ymajor = MAX(ROUND(plsc->majht * plsc->xpmm), 1);
    xminor = MAX(ROUND(plsc->minht * plsc->ypmm), 1);
    yminor = MAX(ROUND(plsc->minht * plsc->xpmm), 1);

    nxsub1 = nxsub;
    nysub1 = nysub;
    xtick1 = llx ? 1.0 : xtick;
    ytick1 = lly ? 1.0 : ytick;

    plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax);
/* n.b. large change; vpwxmi always numerically less than vpwxma, and
 * similarly for vpwymi */
    vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax;
    vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin;
    vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax;
    vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin;

    lax = lax && vpwymi < y0 && y0 < vpwyma ;
    lay = lay && vpwxmi < x0 && x0 < vpwxma ;

/* Calculate tick spacing */

    if (ltx || lgx) 
	pldtik(vpwxmi, vpwxma, &xtick1, &nxsub1);

    if (lty || lgy) 
	pldtik(vpwymi, vpwyma, &ytick1, &nysub1);
/* n.b. large change; xtick1, nxsub1, ytick1, nysub1 always positive. */

/* Set up tick variables */

    if (lix) {
	i1x = xminor;
	i2x = 0;
	i3x = xmajor;
	i4x = 0;
    }
    else {
	i1x = 0;
	i2x = xminor;
	i3x = 0;
	i4x = xmajor;
    }

    if (liy) {
	i1y = yminor;
	i2y = 0;
	i3y = ymajor;
	i4y = 0;
    }
    else {
	i1y = 0;
	i2y = yminor;
	i3y = 0;
	i4y = ymajor;
    }

/* Draw the bottom edge of the box */

    if (lbx) {
	plP_movphy(vppxmi, vppymi);
	if (ltx) {
	    tp = xtick1 * floor(vpwxmi / xtick1);
	    for (;;) {
		tn = tp + xtick1;
		if (lsx) {
		    if (llx) {
			for (i = 0; i <= 7; i++) {
			    temp = tp + xlog[i];
			    if (BETW(temp, vpwxmi, vpwxma))
				plxtik(plP_wcpcx(temp), vppymi, i1x, i2x);
			}
		    }
		    else {
			for (i = 1; i <= nxsub1 - 1; i++) {
			    temp = tp + i * xtick1 / nxsub1;
			    if (BETW(temp, vpwxmi, vpwxma))
				plxtik(plP_wcpcx(temp), vppymi, i1x, i2x);
			}
		    }
		}
		if (!BETW(tn, vpwxmi, vpwxma))
		    break;
		plxtik(plP_wcpcx(tn), vppymi, i3x, i4x);
		tp = tn;
	    }
	}
	plP_draphy(vppxma, vppymi);
    }

/* Draw right-hand edge of box */

    if (lcy) {
	plP_movphy(vppxma, vppymi);
	if (lty) {
	    tp = ytick1 * floor(vpwymi / ytick1);
	    for (;;) {
		tn = tp + ytick1;
		if (lsy) {
		    if (lly) {
			for (i = 0; i <= 7; i++) {
			    temp = tp + xlog[i];
			    if (BETW(temp, vpwymi, vpwyma))
				plytik(vppxma, plP_wcpcy(temp), i2y, i1y);
			}
		    }
		    else {
			for (i = 1; i <= nysub1 - 1; i++) {
			    temp = tp + i * ytick1 / nysub1;
			    if (BETW(temp, vpwymi, vpwyma))
				plytik(vppxma, plP_wcpcy(temp), i2y, i1y);
			}
		    }
		}
		if (!BETW(tn, vpwymi, vpwyma))
		    break;
		plytik(vppxma, plP_wcpcy(tn), i4y, i3y);
		tp = tn;
	    }
	}
	plP_draphy(vppxma, vppyma);
    }

/* Draw the top edge of the box */

    if (lcx) {
	plP_movphy(vppxma, vppyma);
	if (ltx) {
	    tp = xtick1 * (floor(vpwxma / xtick1) + 1);
	    for (;;) {
		tn = tp - xtick1;
		if (lsx) {
		    if (llx) {
			for (i = 7; i >= 0; i--) {
			    temp = tn + xlog[i];
			    if (BETW(temp, vpwxmi, vpwxma))
				plxtik(plP_wcpcx(temp), vppyma, i2x, i1x);
			}
		    }
		    else {
			for (i = nxsub1 - 1; i >= 1; i--) {
			    temp = tn + i * xtick1 / nxsub1;
			    if (BETW(temp, vpwxmi, vpwxma))
				plxtik(plP_wcpcx(temp), vppyma, i2x, i1x);
			}
		    }
		}
		if (!BETW(tn, vpwxmi, vpwxma))
		    break;
		plxtik(plP_wcpcx(tn), vppyma, i4x, i3x);
		tp = tn;
	    }
	}
	plP_draphy(vppxmi, vppyma);
    }

/* Draw left-hand edge of box */

    if (lby) {
	plP_movphy(vppxmi, vppyma);
	if (lty) {
	    tp = ytick1 * (floor(vpwyma / ytick1) + 1);
	    for (;;) {
		tn = tp - ytick1;
		if (lsy) {
		    if (lly) {
			for (i = 7; i >= 0; i--) {
			    temp = tn + xlog[i];
			    if (BETW(temp, vpwymi, vpwyma))
				plytik(vppxmi, plP_wcpcy(temp), i1y, i2y);
			}
		    }
		    else {
			for (i = nysub1 - 1; i >= 1; i--) {
			    temp = tn + i * ytick1 / nysub1;
			    if (BETW(temp, vpwymi, vpwyma))
				plytik(vppxmi, plP_wcpcy(temp), i1y, i2y);
			}
		    }
		}
		if (!BETW(tn, vpwymi, vpwyma))
		    break;
		plytik(vppxmi, plP_wcpcy(tn), i3y, i4y);
		tp = tn;
	    }
	}
	plP_draphy(vppxmi, vppymi);
    }

/* Draw the horizontal axis */

    if (lax) {
	plP_movphy(vppxmi, yp0);
	if (ltx) {
	    tp = xtick1 * floor(vpwxmi / xtick1);
	    for (;;) {
		tn = tp + xtick1;
		if (lsx) {
		    if (llx) {
			for (i = 0; i <= 7; i++) {
			    temp = tp + xlog[i];
			    if (BETW(temp, vpwxmi, vpwxma))
				plxtik(plP_wcpcx(temp), yp0, xminor, xminor);
			}
		    }
		    else {
			for (i = 1; i <= nxsub1 - 1; i++) {
			    temp = tp + i * xtick1 / nxsub1;
			    if (BETW(temp, vpwxmi, vpwxma))
				plxtik(plP_wcpcx(temp), yp0, xminor, xminor);
			}
		    }
		}
		if (!BETW(tn, vpwxmi, vpwxma))
		    break;
		plxtik(plP_wcpcx(tn), yp0, xmajor, xmajor);
		tp = tn;
	    }
	}
	plP_draphy(vppxma, yp0);
    }

/* Draw the vertical axis */

    if (lay) {
	plP_movphy(xp0, vppymi);
	if (lty) {
	    tp = ytick1 * floor(vpwymi / ytick1);
	    for (;;) {
		tn = tp + ytick1;
		if (lsy) {
		    if (lly) {
			for (i = 0; i <= 7; i++) {
			    temp = tp + xlog[i];
			    if (BETW(temp, vpwymi, vpwyma))
				plytik(xp0, plP_wcpcy(temp), yminor, yminor);
			}
		    }
		    else {
			for (i = 1; i <= nysub1 - 1; i++) {
			    temp = tp + i * ytick1 / nysub1;
			    if (BETW(temp, vpwymi, vpwyma))
				plytik(xp0, plP_wcpcy(temp), yminor, yminor);
			}
		    }
		}
		if (!BETW(tn, vpwymi, vpwyma))
		    break;
		plytik(xp0, plP_wcpcy(tn), ymajor, ymajor);
		tp = tn;
	    }
	}
	plP_draphy(xp0, vppyma);
    }

/* Draw grids */

    grid_box(xopt, xtick1, nxsub1, yopt, ytick1, nysub1);

/* Write labels */

    label_box(xopt, xtick1, yopt, ytick1);

/* Restore the clip limits to viewport edge */

    plP_sclp(lxmin, lxmax, lymin, lymax);
}
Esempio n. 5
0
static void
grid_box(const char *xopt, PLFLT xtick1, PLINT nxsub1,
	 const char *yopt, PLFLT ytick1, PLINT nysub1)
{
    PLINT lgx, lhx, llx;
    PLINT lgy, lhy, lly;
    PLFLT vpwxmi, vpwxma, vpwymi, vpwyma;
    PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax;
    PLFLT tn, temp, tcrit, tspace = 0.1;
    PLINT i;

/* Set plot options from input */

    lgx = plP_stsearch(xopt, 'g');
    lhx = plP_stsearch(xopt, 'h');
    llx = plP_stsearch(xopt, 'l');

    lgy = plP_stsearch(yopt, 'g');
    lhy = plP_stsearch(yopt, 'h');
    lly = plP_stsearch(yopt, 'l');

    plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax);
/* n.b. large change; vpwxmi always numerically less than vpwxma, and
 * similarly for vpwymi */
    vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax;
    vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin;
    vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax;
    vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin;

/* Draw grid in x direction. */

    if (lgx) {
	for (tn = xtick1 * floor(vpwxmi/xtick1);
	     tn <= vpwxma; tn += xtick1) {
	    if (lhx) {
		if (llx) {
		    PLFLT otemp = tn;
		    for (i = 0; i <= 7; i++) {
			temp = tn + xlog[i];
			tcrit = (temp - otemp)*tspace;
			otemp = temp;
			if (BETW(temp, vpwxmi+tcrit, vpwxma-tcrit))
			    pljoin(temp, vpwymi, temp, vpwyma);
		    }
		}
		else {
		    for (i = 1; i <= nxsub1 - 1; i++) {
			temp = tn + i * xtick1 / nxsub1;
			tcrit = xtick1 / nxsub1 * tspace;
			if (BETW(temp, vpwxmi+tcrit, vpwxma-tcrit))
			    pljoin(temp, vpwymi, temp, vpwyma);
		    }
		}
	    }
	    tcrit = xtick1*tspace;
	    if (BETW(tn, vpwxmi+tcrit, vpwxma-tcrit))
	        pljoin(tn, vpwymi, tn, vpwyma);
	}
    }

/* Draw grid in y direction */

    if (lgy) {
	tn = ytick1 * floor(vpwymi / ytick1 + tspace);
	for (tn = ytick1 * floor(vpwymi/ytick1);
	     tn <= vpwyma; tn += ytick1) {
	    if (lhy) {
		if (lly) {
		    PLFLT otemp = tn;
		    for (i = 0; i <= 7; i++) {
			temp = tn + xlog[i];
			tcrit = (temp - otemp)*tspace;
			otemp = temp;
			if (BETW(temp, vpwymi+tcrit, vpwyma-tcrit))
			    pljoin(vpwxmi, temp, vpwxma, temp);
		    }
		}
		else {
		    for (i = 1; i <= nysub1 - 1; i++) {
			temp = tn + i * ytick1 / nysub1;
			tcrit = ytick1 / nysub1 * tspace;
			if (BETW(temp, vpwymi+tcrit, vpwyma-tcrit))
			    pljoin(vpwxmi, temp, vpwxma, temp);
		    }
		}
	    }
	    tcrit = ytick1*tspace;
	    if (BETW(tn, vpwymi+tcrit, vpwyma-tcrit))
	    pljoin(vpwxmi, tn, vpwxma, tn);
	}
    }
}