# include <stdio.h>
# include <gfitsio.h>
# include <math.h>
# include <malloc.h>
# include <string.h>
# include <sys/time.h>
# include <stdarg.h>
# include <stdlib.h>
# include <readline/readline.h>
# include <readline/history.h>

# define TRUE (1)
# define FALSE (0)
# define SIGN(X)  (((X) == 0) ? 0 : ((fabs((double)(X))) / (X)))
# define ROUND(X) ((int) ((X) + 0.5*SIGN(X)))
# define SQR(X)   (double) (((double)(X))*((double)(X)))
# define SQ(X)    (double) (((double)(X))*((double)(X)))
# define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
# define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
# define SWAP(X,Y) {double tmp=(X); (X) = (Y); (Y) = tmp;}
# define ISVAR(a) (isalnum (a) || (a == '.') || (a == '_'))
# define ISWORD(a,q) ((q) ? (a != '"') : (isalnum(a) || (a == '.') || (a == '_') || (a == '-')))
# define ISNUM(c) (isdigit(c) || (c == '-') || (c == '.'))

/* Strip WHITESPACE from the start and end of STRING. */
int stripwhite (string)
char *string;
{
  int i;

  if (string == (char *) NULL)
    return (0);

  for (i = 0; OHANA_WHITESPACE (string[i]); i++);

  if (i)
    strcpy (string, string + i);

  i = strlen (string) - 1;

  for (; (i > 0) && OHANA_WHITESPACE (string[i]); i--);

  string[++i] = 0;

  return (i);

}

void main (int argc, char **argv) {

  int i, j, nbytes;
  Header header;
  char filename[1000], buffer[1000];
  char *p;

  /* fprintf (stderr, "starting\n"); */
  while (fscanf (stdin, "%s", filename) != EOF) {
    if (!gfits_read_header (filename, &header)) continue;
    fprintf (stdout, "%s  ", filename);
    for (i = 1; i < argc; i++) {
      bzero (buffer, 1000);
      gfits_scan (&header, argv[i], "%s", 1, buffer);
      stripwhite (buffer);
      fprintf (stdout, "%s  ", buffer);
    }
    fprintf (stdout, "\n");

    gfits_free_header (&header);

  }

}


