/* program to produce input file for reduce */
#include "stdio.h"
main()
{
    struct
	{
    int scan;
	int pixel;
	} size;
    char fname[80],c,buffer[3000];
    int i,recl;
    FILE *rptr,*gptr,*bptr,*fptr;
    puts("\nRSG3 - combines three REMAPP images into a");
    puts("       .CMG input file for REDUCE.");
    puts("\nEnter red file name: ");
	get_f(fname);
    if((rptr = fopen(fname,"rb")) == NULL)
	{
		printf("File not found\n");
		exit(1);
	}                    
    puts("\nEnter green file name: ");
	get_f(fname);
    if((gptr = fopen(fname,"rb")) == NULL)
	{
		printf("File not found\n");
		exit(1);
    }            
    puts("\nEnter blue file name: ");
	get_f(fname);
    if((bptr = fopen(fname,"rb")) == NULL)
	{
		printf("File not found\n");
		exit(1);
    }            
    puts("\nEnter output file name: ");
	get_f(fname);
    if((fptr=fopen(fname,"wb"))==NULL)
    {
	printf("Can't open output file\n");
	exit(1);
    }
    puts("\nEnter number of pixels: ");
    scanf("%u",&size.pixel);
    puts("\nEnter number of scan lines: ");
    scanf("%u",&size.scan);
    fwrite(&size,sizeof(size),1,fptr);
    recl=100;
    if(size.pixel > 100) recl=size.pixel;
    fread(buffer,recl,1,rptr);        /* discard header */
    fread(buffer,recl,1,gptr);        /* discard header */
    fread(buffer,recl,1,bptr);        /* discard header */
    for(i=0;i<size.scan;i++) {
    fread(buffer,recl,1,rptr);
	fwrite(buffer,size.pixel,1,fptr);
    fread(buffer,recl,1,gptr);
	fwrite(buffer,size.pixel,1,fptr);
    fread(buffer,recl,1,bptr);
	fwrite(buffer,size.pixel,1,fptr);
    }
    fclose(rptr);
    fclose(gptr);
    fclose(bptr);
    fclose(fptr);
}
int get_f(name)
char name[];
{
	int i, c_count, flag;
	char c;
	flag = 1;
	while(flag)
	{
		gets(name);
		flag = 0;
	}
}
