
/**************************************************************************
 *                                                                        *
 * Copyright (c) 1996 Michael Richmond and Richard Treffers               *
 *                                                                        *
 *                    This software may be copied and distributed for     *
 *                    educational, research and not for profit services   *
 *                    provided that this copyright and statement are      *
 *                    included in all such copies.                        *
 *                                                                        *
 **************************************************************************/


/*	
	writes comment cards onto the FITS file

		COMMENT filename [ text ... ]

	9/22/92 - usage changed and exit(0) called -rrt
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pcvista.h"
#include "fits.h"

#ifdef PROTO
int main(int, char **);
#else
int main();
#endif

#define USAGE "usage: comment filename [ text ... ] [help]"

int
main(argc, argv)
int argc;
char *argv[];
{
	int i, nrow, ncol;
	char buf[BIG_BUF];
	FITS_HANDLE fh;

	if (argc == 1) {
		error(-1, USAGE);
	}
	if (strcmp(argv[1], "help") == 0) {
		printf("%s\n", USAGE);
		exit(0);
	}

	if (argc == 2)
		error(0, "no comments supplied - inserting empty COMMENT into header");
	fh = fits_open(argv[1], "r+", &nrow, &ncol);
	strcpy(buf, "COMMENT   ");
	for (i = 2; i < argc; i++) {
		sprintf(buf, "%s%s ", buf, argv[i]);
	}
	fits_put_headerline(fh, buf);
	fits_close(fh);
	exit(0);
}
