LOGTEST.C

/****************************************************************************
    (c) 1984 - 2003 by Scientific Endeavors Corporation.
    All rights reserved.

    This program shows an example of a semi-log plot and a log-log plot.
    Note that on the first plot the x axis labels do not start
    on an even decade.
****************************************************************************/

#include <graphic.h>                           /* Include all needed files */

#if TCQ                                 /* Set stack for Borland (Turbo) C */
extern unsigned _stklen = 0x3000;
#endif

/****************************************************************************
    Main program
****************************************************************************/
void GPC_MAIN(void)
{
    float x[301], y[301], z[301];
    float xmin, xmax, ymin, ymax, ystep;
    int i, npts;

    bgnplot(1, 'g', "log.tkf");                  /* GraphiC initialization */
    startplot(MAGENTA);
    metricunits(0);                        /* Ensure scaling in inch units */
    font(3, "simplex.fnt", '\310', "triplex.fnt", '\311',  /* Select fonts */
        "complex.fnt", '\312');
    page(9.0f, 6.884f);                      /* Size of page and plot area */
    area2d(7.6f, 5.5f);
    color(WHITE);                            /* White axis and plot titles */
    xname("\310x");
    yname("\310Trig Functions");
    heading("\311Semi-log Test");
    color(BLACK);                                 /* Black axes and labels */
    xmin = 2.f;                                       /* Define axis limits */
    xmax = 20.f;
    ymin = -1.f;
    ymax = 1;
    ystep = .4f;
    grid(2);                                           /* Dotted line grid */
    fgrid(-1, 2);               /* Subdivide the plot with tick marks only */
    frame(1, 1);                           /* Draw a frame around the plot */
    fntchg((Uchar)'\310');                 /* Change fonts for axes labels */
    xlog(xmin, xmax, "%-1.1f", ymin, ystep, ymax); /* Manual scaled x-axis */
    box();                                   /* Draw a box around the plot */
    npts = 301;                                           /* Generate data */
    for(i = 0; i < npts; i++){
        x[i] = (float)(.001 + .003628 * i * sqrt((double)i));
        y[i] = (float)sin(x[i]);
        z[i] = (float)(.5 * cos(.5 * x[i]));
    }
    color(LGT_GREEN);                                /* Bright green curve */
    curve(x, y, npts, 0);

    color(YELLOW);                                         /* Yellow curve */
    curve((float *)x, (float *)z, npts, 0);
    if (endplot())                                   /* Terminate 1st plot */
        goto EndOfApp;

    startplot(GREEN);                               /* Initialize 2nd plot */
    rotate(1);                                          /* Plot is rotated */
    page(6.884f, 9.0f);                      /* Size of page and plot area */
    area2d(5.7f, 7.4f);
    color(BLACK);                            /* Black plot and axis titles */
    xname("\310x");
    yname("\310y = 1 + xe[x]");
    heading("\312Log-Log Test");
    for(i = 0; i < npts; i++){                     /* Generate data points */
        x[i] = i + 1;
        y[i] = (float)(1. + x[i] * exp((double)x[i] * .01));
    }
    grid(9);                                        /* Fine dot grid lines */
    fgrid(2, 0);                           /* Dotted lines on subdivisions */
    frame(1, 1);           /* Draw a frame around the plot with tick marks */
    lglgscle((float *)x, (float *)y, npts);                /* log-log axes */
    box();                                /* Draw a box around the picture */
    color(RED);                                               /* Red curve */
    tcurve(10);                                          /* Curve is thick */
    curve((float *)x, (float *)y, npts, 0);
    tcurve(0);
    color(LGT_BLUE);                        /* Bright blue date-time stamp */
    dateit((Uchar)'\310');
    endplot();                                 /* GraphiC closing routines */

EndOfApp:
    stopplot();
}