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

/*********************** fits create table *******************************/
int gfits_create_table (Header *header, FTable *table) {

  int Nbytes;
  char type[80];

  gfits_scan (header, "XTENSION", "%s", 1, type);

  table[0].header = header;
  
  Nbytes = gfits_matrix_size (header);
  ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
  if (!strcmp (type, "TABLE")) {
    memset (table[0].buffer, ' ', Nbytes);
  } else {
    memset (table[0].buffer, 0, Nbytes);
  }
  table[0].size = Nbytes;
  return (TRUE);

}

/* init table structure, allocate space for data array (min 1 byte for 0 length) */

/*********************** fits create table *******************************/
int gfits_create_vtable (Header *header, VTable *table, int Nrow) {

  int i, Nx, Ny;
  char type[80];

  gfits_scan (header, "XTENSION", "%s", 1, type);

  table[0].header = header;
  Nx = table[0].header[0].Naxis[0];
  Ny = table[0].header[0].Naxis[0];
  table[0].size = gfits_matrix_size (header);
  table[0].pad = table[0].size - Nx*Ny;
 
  table[0].Nrow = Nrow;
  ALLOCATE (table[0].buffer, char *, MAX (Nrow, 1));
  ALLOCATE (table[0].row, int, MAX (Nrow, 1));
  for (i = 0; i < Nrow; i++) {
    ALLOCATE (table[0].buffer[i], char, Nx);
  }
  return (TRUE);
}

/* init table structure, allocate space for data array (min 1 byte for 0 length) */
