
	/* insert an END card as the 36'th line in a FITS header.  this is
	   to fix files which have no END card in the header, just 36 lines
	   and then data.  we overwrite the 36'th line - too bad. */

#include <stdio.h>

#define CARDLEN 80
#define FIX_POS (35*CARDLEN)

char fixline[CARDLEN + 1];

main(argc, argv)
int argc;
char *argv[];
{
	int i;
	char file[100];

	/* initialize the END card */
	for (i = 0; i < CARDLEN; i++) 
		fixline[i] = ' ';
	fixline[CARDLEN] = '\0';
	fixline[0] = 'E';
	fixline[1] = 'N';
	fixline[2] = 'D';

	for (i = 1; i < argc; i++) {
		strcpy(file, argv[i]);
		fix(file);
	}
}
	


fix(file)
char *file;
{
	FILE *fp, *fopen();

	if ((fp = fopen(file, "r+")) == NULL) {
		fprintf(stderr, "can't open file %s\n", file);
		exit(-1);
	}
	fseek(fp, (long) FIX_POS, 0);
	if (fwrite(fixline, CARDLEN, 1, fp) != 1) {
		fprintf(stderr, "can't write END in file %s\n", file);
		exit(-1);
	}
	fclose(fp);
}
