#ifndef lint
static char *sccsid = "@(#)g_bod.c	1.3 (UKC) 31/3/87";
#endif  lint
#include <stdio.h>
#include <raster.h>
#include <math.h>
#include "extern.h"
#include "macros.h"

/*
 *	g_bod takes a stdio file pointer open to a raster file,
 *	allocates and fills suzie[][], and sets xsue to pic width,
 *	and ysue to pic height.
 *	big and little seem to want to be set to the max and min values
 *	in the image.
 */

g_bod (f)/* credit for this goes to rich stewart, who wanted to
  		do susie in the first place */
FILE * f;
{
    register int x, y;
    double  maxcolour;
    rasfile_t *rfp;
    char *calloc();

    rfp = rasfpopen(f);
    if (rfp == NULL) {
	/* can never happen */
	fputs("Error opening pattern file", stderr);
	exit(1);
    }
    xsue = ras_width(rfp);
    ysue = ras_height(rfp);

    /* allocate space for suzie. first the dope vectors... */
    suzie = (double **) calloc(xsue, sizeof(double *));
    if (suzie == NULL) {
	fputs("Out of memory in g_bod(); pattern too wide.\n", stderr);
	exit(1);
    }
    /* and the columns thenselves */
    for (x=0; x<xsue; x++) {
	suzie[x] = (double *) calloc(ysue, sizeof(double));
	if (suzie[x] == NULL) {
	    fputs("Out of memory in g_bod(); pattern too large.\n", stderr);
	    exit(1);
	}
    }

    maxcolour = ras_ncolours(rfp) - 1;

    /* read in the image */
    for (y = 0; y < ysue; y++) {
	register pixel_t *line;

	line = rasgetline(rfp);
	for (x = 0; x < xsue; x++) {
	    suzie[x][y] = (double) line[x] / maxcolour;
	}
    }
    rasclose(rfp);
}
