#include <stdio.h>
#include <fcntl.h>
main(argc,argv)
int argc;
char *argv[];
{
	FILE *inf1,*outf1;
	char aline[50];
	char outf2[50];
	char inf2[50];
	char line[50];
	int maxline;
	int ch2,x,y,z,pix;
	int pixel;
	int header = 0;
	int fwidth = 1728;
	/*int linein = 4625;*/
	int linein;
	char lines[6];
	
	if (argc!=3) {
		printf("you forgot to enter the filename\n");
                exit();
        }

	sprintf(inf2,"%s",*++argv);
        strcat(inf2,".raw");
	if ((inf1=fopen(inf2,"rb"))==NULL) {
		printf("cannot open file\n");
		exit();
	}
	sprintf(outf2,"%s",*argv);
        strcat(outf2,".tdu");
	printf("Output file name %s\n",outf2);
	/*
	*printf("%s",outf2);
	*printf("%s",*argv);
	*/
	sprintf(lines,"%s",*++argv);
	linein = atoi(lines);
	

	if ((outf1=fopen(outf2,"wb"))==NULL) {
                        printf("cannot write binary file\n");
                        exit();
        }
	fgets(line, maxline, inf1);
	fgets(line, maxline, inf1);
	fgets(line, maxline, inf1);
	fgets(line, maxline, inf1);
	for (z=1;z<=linein;z++) {
	for (x=1;x<=header;x++) {
		ch2=getc(inf1);
		ch2=ch2;
		putc(ch2,outf1);
	}
	for (y=1;y<=fwidth;y++) {
		ch2=getc(inf1);
		ch2=~ch2;
		putc(ch2,outf1);
	}
	}
	fclose(inf1);
	fclose(outf1);
exit();	
}
