MACHII.C

/****************************************************************************
        (c) 1990 by SECA, Inc.
        All rights reserved.

        This program draws a filled contour plot from random data.
****************************************************************************/

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

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

/* These patterns look good on the screen. */
int clr[]={53, 54, 63, 69, 74, 73, 71, 95, 120, 145, 147, 173, 51};

/* These patterns were used to produce the picture in the manual
using PostScript conversion. */
/* int clr[] = {68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 67}; */

/****************************************************************************
        Main program
****************************************************************************/
void GPC_MAIN(void)
{
    FILE *file1= NULL;
    int i, labint = 2, nx = 31, ny = 31;
    float *x = NULL, *y = NULL, *z = NULL;
    float xorig = 0.0f, xstep = 11.0f, xmax = 45.f;
    float yorig = 0.0f, ystep = 5.0f, ymax = 25.f;
    float zorig = 0.0f, zstep = 0.5f, zmax = 5.0f;
    int npts=346;

    x = (float *)gpcalloc(npts, sizeof(float));         /* Allocate arrays */
    y = (float *)gpcalloc(npts, sizeof(float));
    z = (float *)gpcalloc(npts, sizeof(float));
    if (x == NULL || y == NULL || z == NULL){
        GPC_PUTS("MACHII: Could not allocate data arrays");
        goto EndOfApp;
    }

    file1 = gfopen("mach.dat", "r", 0);                 /* Open data file */
    if(file1 == NULL){                                   /* Test for error */
        GPC_PUTS("MACHII: Could not open file MACH.DAT");
        goto EndOfApp;
    }

    for(i = 0; i < npts; i++)                              /* Read in data */
        fscanf(file1, "%e %e %e", &x[i], &y[i], &z[i]);
    gfclose(file1);

    bgnplot(1, 'g', "mach.tkf");                 /* GraphiC initialization */
    startplot(BRT_WHITE);                              /* White background */
    metricunits(0);                        /* Ensure scaling in inch units */

    page(9.0f, 6.884f);                                 /* Page dimensions */
    area2d(7.5f, 5.5f);                            /* x and y axes lengths */
    xorig=0.0f, xstep=15.0f, xmax=45.f;
    yorig=0.0f, ystep=5.0f, ymax=25.f;
    zorig=0.0f, zstep=0.5f, zmax=5.5f;
    nx = 31;
    ny = 31;
    contcolor(clr, 0);
    upright(1);
    labint = 2;                                  /* Contour label interval */
    color(BLACK);                                   /* Set labels to black */
    tfont(5);
    xname("#X#");                                           /* x axis name */
    yname("#Y#");                                           /* y axis name */
    tfont(7);
    heading("#MACH II PLOT#");                               /* Plot title */
    color(RED);                                    /* Set box color to red */
    pbox();                                  /* Draw a box around the plot */
    graf("%-2.2f",xorig,xstep,xmax,"%2.2f",yorig,ystep,ymax);
    color(BLUE);                                     /* Use blue for plots */
    conmatr(x,y,z,npts,xorig,xmax,nx,yorig,ymax,ny,zorig,zstep,zmax,0L,labint);
    endplot();                              /* Get beep and wait for input */
    stopplot();                          /* Terminate plot and close files */

EndOfApp:                                         /* Free allocated memory */
    gpcfree((void **)&x);
    gpcfree((void **)&y);
    gpcfree((void **)&z);
}