# include <ohana.h>
# include <gfitsio.h>
int FT_UNSIGN_MODE;

/*********************** fits read header ***********************************/
int gfits_read_Xheader (char *filename, Header *header, int N) {
  
  /* read header for extension number N */

  FILE *f;
  int j, Nmatrix, Nskip;
  Header theader;
  
  f = fopen (filename, "r");
  if (f == NULL) {
    header[0].buffer = NULL;
    return (FALSE);
  }

  Nskip = 0;
  for (j = -1; j < N; j++) {
    /* load data for this header */
    if (!gfits_load_header (f, &theader)) {
      fclose (f);
      return (FALSE);
    }

    Nmatrix = gfits_matrix_size (&theader);

    /* skip to next header */
    fseek (f, Nmatrix, SEEK_CUR);
    Nskip += (Nmatrix + theader.size);
    gfits_free_header (&theader);
  }
  
  if (!gfits_load_header (f, header)) {
    fclose (f);
    return (FALSE);
  }
  fclose (f);
  Nskip += header[0].size;
  return (Nskip);
}	

