IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2015, 8:15:27 AM (11 years ago)
Author:
eugene
Message:

adding api for adding varlength cell

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_table_varlength.c

    r28241 r38324  
    22# include <gfitsio.h>
    33
     4// fills the column definition structure for a specific column based on a given table.
    45int gfits_varlength_column_define (FTable *ftable, VarLengthColumn *def, int column) {
    56
     
    101102    *length = ptr[0];
    102103    offset = ptr[1];
    103   } else if (column->mode == 'Q') {
     104  }
     105  if (column->mode == 'Q') {
    104106    off_t *ptr;
    105107    ptr = (off_t *) &ftable->buffer[row*Nx + column->Nstart];
    106108    *length = ptr[0];
    107109    offset = ptr[1];
    108   } else {
    109         // this was actually trapped above
    110         abort();
    111110  }
    112111
     
    114113  return result;
    115114}
     115
     116// to generate a compressed image or a compressed table, we need to be able to add data
     117// for varlength columns to the heap.  To start, assume we have defined the cartesian
     118// portion of the table correctly, and are only extending the heap.
     119
     120// XXX NOTE: this function assumes the table data is currently in local byte swap order.
     121// swap before writing out
     122
     123// Here are operations we need to do:
     124
     125int gfits_varlength_column_add_data (FTable *table, char *data, off_t Ndata, int row) {
     126
     127  // find the current starting point for new data (end of current buffer main data + current heap
     128  off_t heap_offset = gfits_data_min_size (table->header);
     129  char *heap_ptr = ftable->buffer + heap_offset;
     130
     131  // extend the buffer size to add the new data
     132  off_t Nbytes = heap_offset + Ndata;
     133  REALLOCATE (table->buffer, char, Nbytes);
     134
     135  // add the new data to the table buffer
     136  memcpy (heap_ptr, data, Ndata);
     137
     138  // *** now we add the data description to the table ***
     139
     140  if ((column->mode != 'P') && (column->mode != 'Q')) abort();
     141
     142  // find the cell for the specified row & column
     143  // the values in the main table for this row and varlength column:
     144  Nx = ftable->header->Naxis[0];
     145
     146  // set the cell values
     147  if (column->mode == 'P') {
     148    int *ptr;
     149    ptr = (int *) &ftable->buffer[row*Nx + column->Nstart];
     150    ptr[0] = Ndata;
     151    ptr[1] = heap_offset;
     152  }
     153  if (column->mode == 'Q') {
     154    off_t *ptr;
     155    ptr = (off_t *) &ftable->buffer[row*Nx + column->Nstart];
     156    ptr[0] = Ndata;
     157    ptr[1] = heap_offset;
     158  }
     159
     160  // update maxlen
     161  column->maxlen = MAX (column->maxlen, Ndata);
     162
     163  return TRUE;
     164}
Note: See TracChangeset for help on using the changeset viewer.