/* GDCHART 0.95b  3D Bar sample  09 Aug 1999 */

#include <stdio.h>
 
#include "gdc.h"
#include "gdchart.h"
 
main()
{
    int             num_points = 5,
                    num_sets   = 2;

    float           data  [ num_sets ][ num_points ];
    unsigned long   extclr[ num_sets ][ num_points ];
    char            *lbls[ ] = { "Fred", "Dino", "Mr.\nSlate", "Barney", "Wilma" };
 
    get_data( num_sets, num_points, data );
    get_individual_colors( num_sets, num_points, extclr );

    GDC_ExtColor  = &(extclr[0][0]);            /* set color option */
    GDC_bar_width = 60;                         /* (%)              */

//  printf( "Content-Type: image/gif\n\n" );    /* mime type (CGI) */

                                    /* ---- call the lib V0.94b ----- */
        out_graph( 200, 175,        /* width, height           */
                   stdout,          /* open FILE pointer       */
                   GDC_3DBAR,       /* chart type              */
                   num_points,      /* num points per data set */
                   lbls,            /* X labels array of char* */
                   2,               /* number of data sets     */
                   &(data[0][0]),   /* dataset 1               */
                   &(data[1][0]) ); /* dataset 2               */

//                                  /* ---- call the lib V0.95b ----- */
//  GDC_out_graph( 200, 175,        /* width, height */
//                 stdout,          /* open FILE pointer       */
//                 GDC_3DBAR,       /* chart type              */
//                 num_points,      /* num points per data set */
//                 lbls,            /* X labels array of char* */
//                 num_sets,        /* number of data sets     */
//                 (float*)data,    /* data                    */
//                 (float*)NULL );  /* no right-hand-axis data */

    exit(0);
}

/* --------------------------------------------------------- */
/* sample data gathering routine                             */
/* data can come from anywhere, generally a DB or data file  */
/* here it's randomly generated                              */
/* --------------------------------------------------------- */
#include <stdlib.h>     /* for rand() */
#include <time.h>       /* for seed   */
get_data( int   num_sets,
                   int   num_points,
                   float data[num_sets][num_points] )
{
    int i, j;
    srand( (unsigned int)time((time_t)NULL) );
    for( i=0; i<num_sets; ++i )
        for( j=0; j<num_points; ++j )
            /* random number between 0 & 500 */
            data[i][j] = 1.0+(500.0 * rand()/(RAND_MAX+1.0));
}

/* -------- also random colors ----------------------------- */
get_individual_colors( int           num_sets,
                       int           num_points,
                       unsigned long extclr[num_sets][num_points] )
{
    int i, j;
    for( i=0; i<num_sets; ++i )
        for( j=0; j<num_points; ++j )
            extclr[i][j] = (unsigned long)rand();
}