# include <ohana.h>
# include <gfitsio.h>

off_t gfits_data_size (Header *header) {
  
  int i;
  off_t Nrec, size;

  if (header[0].Naxes == 0) return (0);

  size = abs(header[0].bitpix / 8);

  for (i = 0; i < header[0].Naxes; i++)
    size *= header[0].Naxis[i];

  // XXX do I multiply this times gcount?
  size += header[0].pcount;

  /* round up to next complete block */
  if (size % FT_RECORD_SIZE) {
    Nrec = 1 + (int) (size / FT_RECORD_SIZE);
    size = FT_RECORD_SIZE * Nrec;
  }

  return (size);
}

off_t gfits_data_min_size (Header *header) {
  
  int i;
  off_t size;

  if (header[0].Naxes == 0) return (0);

  size = abs(header[0].bitpix / 8);

  for (i = 0; i < header[0].Naxes; i++)
    size *= header[0].Naxis[i];

  // XXX do I multiply this times gcount?
  size += header[0].pcount;

  return (size);
}

off_t gfits_data_pad_size (off_t rawsize) {
  
  off_t Nrec, size;

  size = rawsize;

  /* round up to next complete block */
  if (rawsize % FT_RECORD_SIZE) {
    Nrec = 1 + (int) (rawsize / FT_RECORD_SIZE);
    size = FT_RECORD_SIZE * Nrec;
  }

  return (size);
}
