
	/* given a file which consists of a pseudo-FITS header and then
	   some stuff, print only the pseudo-FITS header.

	            printheader file 
	*/

#include <stdio.h>
#include <ctype.h>
#include "pf.h"
#include "header.h"

char err_msg[BIG_BUF];
char usage[] = "usage: printheader file ";

main(argc, argv)
int argc;
char *argv[];
{
	int type;
	char outfile[BIG_BUF], *gotit, *find();
	
	strcpy(outfile, "");

	if (argc != 2) {
		fprintf(stderr, "%s\n", usage);
		exit(1);
	}
		
	if ((type = fits_file_type(argv[1])) != PSEUDO_FITS) {
		fprintf(stderr, "file %s does not have a pseudo-FITS header\n", 
						argv[1]);
		exit(1);
	}
	print_header(argv[1]);
}

	/* copy all the header information from a pseudo-FITS file into
	   a pseudo-FITS form (with newlines at the end of each 80-char
	   line) and send to stdout */

int
print_header(fitsfile)
char *fitsfile;
{
	FILE *fits_fp, *out_fp;
	char line[BIG_BUF + 1];
	
	if ((fits_fp = fopen(fitsfile, "r")) == NULL) {
		sprintf(err_msg, "can't open pseudo-FITS file %s\n", fitsfile);
		die(err_msg);
	}
	out_fp = stdout;

	line[BIG_BUF] = '\0';
	while (fgets(line, BIG_BUF, fits_fp) != NULL) {
		fprintf(out_fp, "%s", line);
		if (strncmp(line, "END", 3) == 0)
			break;
	}
	fclose(fits_fp);

	return(0);
}

