#include <string.h>
#include <stdio.h>
#include "fitsio.h"

int main(int argc, char *argv[])
{
    fitsfile *fptr;         
    char card[FLEN_CARD]; 
    int  nkeys, ii, status = 0;  /* MUST initialize status */

    if (argc < 2)
    {
      printf("Error in execution of 'read_header.c'. Filename not found..") ;
      exit(0) ;  
    }  

   if (argc > 2)
    {
      printf("Error in execution of 'read_header.c'. Extra Arguments found. Filename might have spaces..") ;
      exit(0) ;  
    }   

    fits_open_file(&fptr, argv[1], READONLY, &status);
    if(status)
      {
        printf("report_error_status:%d\n", status) ;
        exit(0) ; 
      }  

    fits_get_hdrspace(fptr, &nkeys, NULL, &status);
      if(status)
      {
        printf("report_error_status:%d\n", status) ;
        exit(0) ; 
      } 

    for (ii = 1; ii <= nkeys; ii++)  { 
       fits_read_record(fptr, ii, card, &status); /* read keyword */
        if(status)
        {
          printf("report_error_status:%d\n", status) ;
          exit(0) ; 
      } 
       printf("%s\n", card);
    }
    printf("END\n\n");  /* terminate listing with END */

    fits_close_file(fptr, &status);
    if(status)
      {
        printf("report_error_status:%d\n", status) ;
        exit(0) ; 
      }
   return(status);
}
