#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
This simple program generates a binary IMA formatted file
for use by the image analysis feature.

Kenneth Moore 7-27-93

*/

#define NUMPIXELS 6
#define NUMCOLORS 3

void main(void)
{
int color, row, col;
short number;
unsigned char xbyte;
FILE *out;

/* STEP 1. First open the file */

out = fopen("SAMPLE.IMA", "wb");

/* STEP 2. Write a zero for the first 16-bit integer */
number = 0;
fwrite(&number, 2, 1, out);

/* STEP 3. Write the number of pixels */
number = NUMPIXELS;
fwrite(&number, 2, 1, out);

/* STEP 4. Write the number of colors */
number = NUMCOLORS;
fwrite(&number, 2, 1, out);

/* STEP 5. For each color, write out n x n pixels */
for (color = 0; color < NUMCOLORS; color++)
	{
	for (row = 0; row < NUMPIXELS; row++)
		{
		for (col = 0; col < NUMPIXELS; col++)
			{
			if (col / (NUMPIXELS/NUMCOLORS) == color) xbyte = 255;
			else xbyte = 0;
			fputc(xbyte, out);
			/*
			printf("%i %i %i %i\n",color, row, col, xbyte);
			getch();
			*/
			}
		}
	}

/* STEP 6. Close the file */
fclose(out);
}