IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38366


Ignore:
Timestamp:
Jun 4, 2015, 5:42:47 PM (11 years ago)
Author:
eugene
Message:

libfits compressed I/O seems to be generally working

Location:
branches/eam_branches/ohana.20150429/src/libfits
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/include/gfitsio.h

    r38356 r38366  
    191191
    192192int     gfits_uncompress_image         PROTO((Header *header, Matrix *matrix, FTable *ftable));
    193 int     gfits_uncompress_data          PROTO((char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize));
     193int     gfits_uncompress_data          PROTO((char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int Nout_alloc, int out_pixsize));
    194194int     gfits_distribute_data          PROTO((Matrix *matrix, char *data, int Ndata, int bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero));
    195195
     
    244244int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal));
    245245int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
     246int     gfits_get_bintable_column_raw  PROTO((Header *header, FTable *table, char *label, void **data, char nativeOrder));
    246247int     gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval));
     248void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));
    247249int     gfits_get_bintable_column_type_by_N  PROTO((Header *header, int N, char *type, int *Nval));
    248 void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));
     250void   *gfits_get_bintable_column_data_raw   PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol, char nativeOrder));
    249251int     gfits_get_table_column         PROTO((Header *header, FTable *table, char *label, void **data));
    250252int     gfits_get_table_column_type    PROTO((Header *header, char *label, char *type));
     
    252254int     gfits_read_table               PROTO((char *filename, FTable *ftable));
    253255int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    254 int     gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow));
     256int     gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder));
    255257int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    256258int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4);
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c

    r38363 r38366  
    165165
    166166  // define compression-specific keywords, update header as needed.
    167   if (!strcasecmp(zcmptype, "RICE_1")) {
     167  if (!strcasecmp(zcmptype, "RICE_1") || !strcasecmp(zcmptype, "RICE_ONE")) {
    168168    if (!gfits_modify (theader, "ZNAME1", "%s", 1, "BLOCKSIZE")) ESCAPE;
    169169    if (!gfits_modify (theader, "ZVAL1", "%d", 1, 32)) ESCAPE;
     
    195195    // copy the raw pixels from their native matrix locations to the temporary output buffer
    196196    // for float -> int scaling by zscale, zzero may be applied
    197     if (!strcasecmp (zcmptype, "GZIP_2")) {
     197    if (!strcasecmp (zcmptype, "GZIP_2") || !strcasecmp (zcmptype, "NONE_2")) {
    198198      if (!gfits_collect_gzp2 (matrix, raw, Nraw, raw_bitpix, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE;
    199199    } else {
     
    240240    // compression modes require swapping after compression (compresssion & decompression
    241241    // operate on native ENDIAN)
    242     if (strcasecmp(zcmptype, "GZIP_1") && strcasecmp(zcmptype, "GZIP_2") && strcasecmp(zcmptype, "RICE_1")) {
     242    if (strcasecmp(zcmptype, "NONE") &&
     243        strcasecmp(zcmptype, "NONE_2") &&
     244        strcasecmp(zcmptype, "GZIP_1") &&
     245        strcasecmp(zcmptype, "GZIP_2") &&
     246        strcasecmp(zcmptype, "RICE_1") &&
     247        strcasecmp(zcmptype, "RICE_ONE")) {
    243248      // Nzdata is number of bytes
    244249      if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_data.c

    r38362 r38366  
    4242
    4343  // do not actually compress : this is used for testing
    44   if (!strcasecmp(cmptype, "NONE")) {
     44  if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_2")) {
    4545    unsigned long Nbytes = Nrawpix * rawpix_size;
    4646
     
    8585    // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum);
    8686
    87     char buffer[1000];
    8887    int k;
    8988
     
    101100          fprintf (stderr, "Nout: %d, Nrawpix: %d\n", Nout, Nrawpix);
    102101          fprintf (stderr, "cmp inp: ");
    103           for (k = 0; k < Nout; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     102          for (k = 0; k < Nout; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 2) fprintf (stderr, " "); }
    104103          fprintf (stderr, "\n");
    105104        }
    106 
    107         status = fits_rdecomp_short ((unsigned char *) zdata, Nout, (unsigned short *) buffer, Nrawpix, blocksize);
    108         myAssert (!status, "failed to rdecomp");
    109105        break;
    110106
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c

    r38356 r38366  
    174174
    175175  if (!strcasecmp(cmptype, "NONE")) return TRUE;
     176  if (!strcasecmp(cmptype, "NONE_2")) return TRUE; // do not compress, but shuffle a la GZIP_2
    176177  if (!strcasecmp(cmptype, "GZIP_1")) return TRUE;
    177178  if (!strcasecmp(cmptype, "GZIP_2")) return TRUE;
     
    190191  if (!strcasecmp(cmptype, "GZIP_1") ||
    191192      !strcasecmp(cmptype, "GZIP_2") ||
     193      !strcasecmp(cmptype, "NONE_2") ||
    192194      !strcasecmp(cmptype, "NONE")) {
    193195    if (out_bitpix ==   8) return (1);
     
    235237  if (!strcasecmp(cmptype, "GZIP_1") ||
    236238      !strcasecmp(cmptype, "GZIP_2") ||
     239      !strcasecmp(cmptype, "NONE_2") ||
    237240      !strcasecmp(cmptype, "NONE")) {
    238241    if (out_bitpix ==   8) return (1);
     
    280283  if (!strcasecmp(cmptype, "GZIP_1") ||
    281284      !strcasecmp(cmptype, "GZIP_2") ||
     285      !strcasecmp(cmptype, "NONE_2") ||
    282286      !strcasecmp(cmptype, "NONE")) {
    283287    return (out_bitpix);
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c

    r38363 r38366  
    271271
    272272    // expected output size for this tile
    273     // Nout = gfits_tile_size (matrix, otile, ztile);
    274     Nout = Nout_alloc;
     273    Nout = raw_pixsize*gfits_tile_size (matrix, otile, ztile);
    275274
    276275    zdata = gfits_varlength_column_pointer (ftable, &zdef, row, &Nzdata);
     
    284283    }
    285284
    286     if (strcasecmp(cmptype, "GZIP_1") && strcasecmp(cmptype, "GZIP_2") && strcasecmp(cmptype, "RICE_1")) {
     285    if (strcasecmp(cmptype, "NONE") &&
     286        strcasecmp(cmptype, "NONE_2") &&
     287        strcasecmp(cmptype, "GZIP_1") &&
     288        strcasecmp(cmptype, "GZIP_2") &&
     289        strcasecmp(cmptype, "RICE_1") &&
     290        strcasecmp(cmptype, "RICE_ONE")) {
    287291      // Nzdata is number of bytes
    288292      if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
     
    300304    // XXX the tile must not be > 2GB
    301305    // Nout going in is number of bytes
    302     if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, raw_pixsize)) ESCAPE;
     306    if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, Nout_alloc, raw_pixsize)) ESCAPE;
    303307
    304308    if (VERBOSE_DUMP && (row == 0)) {
     
    323327
    324328    // copy the uncompressed pixels into their correct locations           
    325     if (!strcasecmp(cmptype, "GZIP_2")) {
     329    if (!strcasecmp(cmptype, "GZIP_2") || !strcasecmp(cmptype, "NONE_2")) {
    326330      if (!gfits_distribute_gzp2 (matrix, out, Nout, raw_bitpix, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE;
    327331    } else {
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_data.c

    r38362 r38366  
    2828# define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
    2929
    30 int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize) {
     30int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int Nout_alloc, int out_pixsize) {
    3131
    3232  int status;
    3333
    3434  // do not actually uncompress : this is used for testing
    35   if (!strcasecmp(cmptype, "NONE")) {
     35  if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_2")) {
    3636    memcpy (outdata, zdata, Nzdata);
     37    myAssert (*Nout == Nzdata, "invalid size");
    3738    *Nout = Nzdata / out_pixsize;
    3839    return (TRUE);
     
    4243    // unsigned long tNout = *Nout * out_pixsize;
    4344    // input value of *Nout is number of BYTES
    44     unsigned long tNout = *Nout;
     45    unsigned long tNout = Nout_alloc;
    4546
    4647    // for GZIP data, I need to check for and remove the header on the first block:
     
    5253    status = gfits_uncompress ((Bytef *) outdata, &tNout, (Bytef *) zdata, Nzdata);
    5354    if (status != Z_OK) ESCAPE(FALSE);
     55    myAssert (*Nout == tNout, "uncompressed size mismatch");
    5456    *Nout = tNout / out_pixsize;
    5557    // output value of *Nout is number of PIXELS
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c

    r38363 r38366  
    22# include <gfitsio.h>
    33# include <zlib.h>
     4# define VERBOSE_DUMP 0
    45
    56// the user needs to specify the various compression options:
     
    3637
    3738  int Ntile, ztilelast;
     39  if (!ztilelen) ztilelen = srcheader->Naxis[1];
     40
    3841  if (srcheader->Naxis[1] % ztilelen) {
    3942    Ntile = srcheader->Naxis[1] / ztilelen + 1;
     
    7578    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE;
    7679
    77     // XXX this should depend on the field type, but for now just use a single type (GZIP_1)
     80    // for now we set all fields to the requested type
    7881    strcpy (fields[i].zctype, zcmptype);
    7982
     
    125128    max_width = MAX(max_width, fields[i].rowsize);
    126129
     130    // RICE can only be used on integer fields
     131    if (!strcasecmp (fields[i].zctype, "RICE_1") || !strcasecmp (fields[i].zctype, "RICE_ONE")) {
     132      if (!strcmp (fields[i].datatype, "float") || !strcmp (fields[i].datatype, "double")) {
     133        strcpy (fields[i].zctype, "GZIP_2");
     134      }
     135    }
     136
    127137    // compression type per column (XXX for now we are just using zcmptype, as set above)
    128138    snprintf (keyword, 81, "ZCTYP%d", i+1);
     
    152162
    153163      // copy the raw pixels from their native matrix locations to the temporary output buffer
    154       if (!strcasecmp(fields[i].zctype, "GZIP_2")) {
     164      if (!strcasecmp(fields[j].zctype, "GZIP_2") || !strcasecmp(fields[j].zctype, "NONE_2")) {
    155165        if (!gfits_collect_table_gzp2 (srctable, &fields[j], raw, row_start, Nrows)) ESCAPE;
    156166      } else {
     
    158168      }
    159169     
     170      if (VERBOSE_DUMP) {
     171        int k;
     172        fprintf (stderr, "c1: ");
     173        for (k = 0; k < Nrows*fields[j].Nvalues*fields[j].pixsize; k++) {
     174          fprintf (stderr, "%02hhx", raw[k]);
     175          if (k % 2) fprintf (stderr, " ");
     176          // if (k % 32 == 31) fprintf (stderr, "\n");
     177        }
     178        fprintf (stderr, "\n");
     179      }
     180
    160181      // optname, optvalue = NULL, Noptions = 0
    161182     
    162183      int Nraw = Nrows*fields[j].Nvalues; // number of pixels
    163       if (!strcmp(fields[j].zctype, "GZIP_1")) {
     184      if (!strcasecmp(fields[j].zctype, "GZIP_1")) {
    164185        if (!gfits_byteswap_zdata (raw, Nraw * fields[j].pixsize, fields[j].pixsize)) ESCAPE;
     186      }
     187
     188      if (VERBOSE_DUMP) {
     189        int k;
     190        fprintf (stderr, "c2: ");
     191        for (k = 0; k < Nrows*fields[j].Nvalues*fields[j].pixsize; k++) {
     192          fprintf (stderr, "%02hhx", raw[k]);
     193          if (k % 2) fprintf (stderr, " ");
     194          // if (k % 32 == 31) fprintf (stderr, "\n");
     195        }
     196        fprintf (stderr, "\n");
    165197      }
    166198
     
    168200      if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE;
    169201     
    170       if (strcasecmp(fields[j].zctype, "GZIP_1") && strcasecmp(fields[j].zctype, "GZIP_2") && strcasecmp(fields[j].zctype, "RICE_1")) {
     202      if (VERBOSE_DUMP) {
     203        int k;
     204        fprintf (stderr, "c3: ");
     205        for (k = 0; k < Nzdata; k++) {
     206          fprintf (stderr, "%02hhx", zdata[k]);
     207          if (k % 2) fprintf (stderr, " ");
     208          // if (k % 32 == 31) fprintf (stderr, "\n");
     209        }
     210        fprintf (stderr, "\n");
     211      }
     212
     213      if (strcasecmp(fields[j].zctype, "NONE") &&
     214          strcasecmp(fields[j].zctype, "NONE_2") &&
     215          strcasecmp(fields[j].zctype, "GZIP_1") &&
     216          strcasecmp(fields[j].zctype, "GZIP_2") &&
     217          strcasecmp(fields[j].zctype, "RICE_1") &&
     218          strcasecmp(fields[j].zctype, "RICE_ONE")) {
    171219        if (!gfits_byteswap_zdata (zdata, Nzdata, fields[j].pixsize)) ESCAPE;
     220      }
     221
     222      if (VERBOSE_DUMP) {
     223        int k;
     224        fprintf (stderr, "c4: ");
     225        for (k = 0; k < Nzdata; k++) {
     226          fprintf (stderr, "%02hhx", zdata[k]);
     227          if (k % 2) fprintf (stderr, " ");
     228          // if (k % 32 == 31) fprintf (stderr, "\n");
     229        }
     230        fprintf (stderr, "\n");
    172231      }
    173232
     
    228287    for (i = 0; i < Nrows; i++) {
    229288      int row = row_start + i;
    230       char *tgt = &raw[i*field->rowsize + k*Nrows*field->Nvalues];
    231       char *src = &table->buffer[Nx*row + field->offset + k];
    232       for (j = 0; j < field->Nvalues; j++, tgt+=field->pixsize, src++) {
    233         *tgt = *src;
    234         myAssert (src - raw < field->
     289      char *rawptr = &raw[i*field->Nvalues + k*Nrows*field->Nvalues];
     290# ifdef BYTE_SWAP     
     291      char *tblptr = &table->buffer[Nx*row + field->offset + (field->pixsize - k - 1)];
     292# else
     293      char *tblptr = &table->buffer[Nx*row + field->offset + k];
     294# endif
     295      for (j = 0; j < field->Nvalues; j++, tblptr += field->pixsize, rawptr++) {
     296        *rawptr = *tblptr;
     297        myAssert (rawptr - raw < Nrows*field->Nvalues*field->pixsize, "oops");
     298        myAssert (tblptr - table->buffer < table->header->Naxis[0]*table->header->Naxis[1], "oops");
    235299      }
    236300    }
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_get_column.c

    r38325 r38366  
    1717
    1818void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol) {
     19  void *data = gfits_get_bintable_column_data_raw (header, table, label, type, Nrow, Ncol, FALSE);
     20  return data;
     21}
     22
     23void *gfits_get_bintable_column_data_raw (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol, char nativeOrder) {
    1924
    2025  off_t Nx, Ny;
     
    8792    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    8893# ifdef BYTE_SWAP
    89       SWAP_BYTE;
     94      if (!nativeOrder) { SWAP_BYTE; }
    9095# endif
    9196      *(short *)Pout = *(short *)Pin*Bscale + Bzero;
     
    95100    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    96101# ifdef BYTE_SWAP
    97       SWAP_WORD;
     102      if (!nativeOrder) { SWAP_WORD; }
    98103# endif
    99104      *(int *)Pout = *(int *)Pin*Bscale + Bzero;
     
    104109      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    105110# ifdef BYTE_SWAP
    106         SWAP_DBLE;
     111        if (!nativeOrder) { SWAP_DBLE; }
    107112# endif
    108113        *(int64_t *)Pout = *(int64_t *)Pin;
     
    111116      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    112117# ifdef BYTE_SWAP
    113         SWAP_DBLE;
     118        if (!nativeOrder) { SWAP_DBLE; }
    114119# endif
    115120        *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
     
    120125    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    121126# ifdef BYTE_SWAP
    122       SWAP_WORD;
     127      if (!nativeOrder) { SWAP_WORD; }
    123128# endif
    124129      *(float *)Pout = *(float *)Pin*Bscale + Bzero;
     
    128133    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    129134# ifdef BYTE_SWAP
    130       SWAP_DBLE;
     135      if (!nativeOrder) { SWAP_DBLE; }
    131136# endif
    132137      *(double *)Pout = *(double *)Pin*Bscale + Bzero;
     
    176181  if (!gfits_get_bintable_column_type_by_N (header, N, type, Nval)) return FALSE;
    177182  return (TRUE);
     183}
     184
     185/***********************/
     186int gfits_get_bintable_column_raw (Header *header, FTable *table, char *label, void **data, char nativeOrder) {
     187
     188  char type[16];
     189  off_t Nrow;
     190  int Ncol;
     191
     192  char *array = gfits_get_bintable_column_data_raw (header, table, label, type, &Nrow, &Ncol, nativeOrder);
     193  if (array == NULL) return (FALSE);
     194
     195  *data = array;
     196  return TRUE;
    178197}
    179198
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_set_column.c

    r38329 r38366  
    175175
    176176/***********************/
    177 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow) {
     177// convert the input data array (of the specified intype) to the desired table data type. swap unless nativeOrder is requested
     178int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder) {
    178179
    179180  off_t Nx, Ny;
     
    256257      *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
    257258# ifdef BYTE_SWAP
    258       SWAP_BYTE;
     259      if (!nativeOrder) { SWAP_BYTE; }
    259260# endif
    260261    } 
     
    265266      *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
    266267# ifdef BYTE_SWAP
    267       SWAP_WORD;
     268      if (!nativeOrder) { SWAP_WORD; }
    268269# endif
    269270    }
     
    274275      *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
    275276# ifdef BYTE_SWAP
    276       SWAP_DBLE;
     277      if (!nativeOrder) { SWAP_DBLE; }
    277278# endif
    278279    }
     
    283284      *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
    284285# ifdef BYTE_SWAP
    285       SWAP_WORD;
     286      if (!nativeOrder) { SWAP_WORD; }
    286287# endif
    287288    }
     
    292293      *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
    293294# ifdef BYTE_SWAP
    294       SWAP_DBLE;
     295      if (!nativeOrder) { SWAP_DBLE; }
    295296# endif
    296297    }
     
    315316      *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
    316317# ifdef BYTE_SWAP
    317       SWAP_BYTE;
     318      if (!nativeOrder) { SWAP_BYTE; }
    318319# endif
    319320    } 
     
    324325      *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
    325326# ifdef BYTE_SWAP
    326       SWAP_WORD;
     327      if (!nativeOrder) { SWAP_WORD; }
    327328# endif
    328329    }
     
    333334      *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
    334335# ifdef BYTE_SWAP
    335       SWAP_DBLE;
     336      if (!nativeOrder) { SWAP_DBLE; }
    336337# endif
    337338    }
     
    342343      *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
    343344# ifdef BYTE_SWAP
    344       SWAP_WORD;
     345      if (!nativeOrder) { SWAP_WORD; }
    345346# endif
    346347    }
     
    351352      *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
    352353# ifdef BYTE_SWAP
    353       SWAP_DBLE;
     354      if (!nativeOrder) { SWAP_DBLE; }
    354355# endif
    355356    }
     
    374375      *(short *)Pout = (*(short *)Pin - Bzero) / Bscale;
    375376# ifdef BYTE_SWAP
    376       SWAP_BYTE;
     377      if (!nativeOrder) { SWAP_BYTE; }
    377378# endif
    378379    } 
     
    383384      *(int *)Pout = (*(short *)Pin - Bzero) / Bscale;
    384385# ifdef BYTE_SWAP
    385       SWAP_WORD;
     386      if (!nativeOrder) { SWAP_WORD; }
    386387# endif
    387388    }
     
    392393      *(int64_t *)Pout = (*(short *)Pin - Bzero) / Bscale;
    393394# ifdef BYTE_SWAP
    394       SWAP_DBLE;
     395      if (!nativeOrder) { SWAP_DBLE; }
    395396# endif
    396397    }
     
    401402      *(float *)Pout = (*(short *)Pin - Bzero) / Bscale;
    402403# ifdef BYTE_SWAP
    403       SWAP_WORD;
     404      if (!nativeOrder) { SWAP_WORD; }
    404405# endif
    405406    }
     
    410411      *(double *)Pout = (*(short *)Pin - Bzero) / Bscale;
    411412# ifdef BYTE_SWAP
    412       SWAP_DBLE;
     413      if (!nativeOrder) { SWAP_DBLE; }
    413414# endif
    414415    }
     
    433434      *(short *)Pout = (*(int *)Pin - Bzero) / Bscale;
    434435# ifdef BYTE_SWAP
    435       SWAP_BYTE;
     436      if (!nativeOrder) { SWAP_BYTE; }
    436437# endif
    437438    } 
     
    442443      *(int *)Pout = (*(int *)Pin - Bzero) / Bscale;
    443444# ifdef BYTE_SWAP
    444       SWAP_WORD;
     445      if (!nativeOrder) { SWAP_WORD; }
    445446# endif
    446447    }
     
    451452      *(int64_t *)Pout = (*(int *)Pin - Bzero) / Bscale;
    452453# ifdef BYTE_SWAP
    453       SWAP_DBLE;
     454      if (!nativeOrder) { SWAP_DBLE; }
    454455# endif
    455456    }
     
    460461      *(float *)Pout = (*(int *)Pin - Bzero) / Bscale;
    461462# ifdef BYTE_SWAP
    462       SWAP_WORD;
     463      if (!nativeOrder) { SWAP_WORD; }
    463464# endif
    464465    }
     
    469470      *(double *)Pout = (*(int *)Pin - Bzero) / Bscale;
    470471# ifdef BYTE_SWAP
    471       SWAP_DBLE;
     472      if (!nativeOrder) { SWAP_DBLE; }
    472473# endif
    473474    }
     
    492493      *(short *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    493494# ifdef BYTE_SWAP
    494       SWAP_BYTE;
     495      if (!nativeOrder) { SWAP_BYTE; }
    495496# endif
    496497    } 
     
    501502      *(int *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    502503# ifdef BYTE_SWAP
    503       SWAP_WORD;
     504      if (!nativeOrder) { SWAP_WORD; }
    504505# endif
    505506    }
     
    510511      *(int64_t *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    511512# ifdef BYTE_SWAP
    512       SWAP_DBLE;
     513      if (!nativeOrder) { SWAP_DBLE; }
    513514# endif
    514515    }
     
    519520      *(float *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    520521# ifdef BYTE_SWAP
    521       SWAP_WORD;
     522      if (!nativeOrder) { SWAP_WORD; }
    522523# endif
    523524    }
     
    528529      *(double *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    529530# ifdef BYTE_SWAP
    530       SWAP_DBLE;
     531      if (!nativeOrder) { SWAP_DBLE; }
    531532# endif
    532533    }
     
    551552      *(short *)Pout = (*(float *)Pin - Bzero) / Bscale;
    552553# ifdef BYTE_SWAP
    553       SWAP_BYTE;
     554      if (!nativeOrder) { SWAP_BYTE; }
    554555# endif
    555556    } 
     
    560561      *(int *)Pout = (*(float *)Pin - Bzero) / Bscale;
    561562# ifdef BYTE_SWAP
    562       SWAP_WORD;
     563      if (!nativeOrder) { SWAP_WORD; }
    563564# endif
    564565    }
     
    569570      *(int64_t *)Pout = (*(float *)Pin - Bzero) / Bscale;
    570571# ifdef BYTE_SWAP
    571       SWAP_DBLE;
     572      if (!nativeOrder) { SWAP_DBLE; }
    572573# endif
    573574    }
     
    578579      *(float *)Pout = (*(float *)Pin - Bzero) / Bscale;
    579580# ifdef BYTE_SWAP
    580       SWAP_WORD;
     581      if (!nativeOrder) { SWAP_WORD; }
    581582# endif
    582583    }
     
    587588      *(double *)Pout = (*(float *)Pin - Bzero) / Bscale;
    588589# ifdef BYTE_SWAP
    589       SWAP_DBLE;
     590      if (!nativeOrder) { SWAP_DBLE; }
    590591# endif
    591592    }
     
    610611      *(short *)Pout = (*(double *)Pin - Bzero) / Bscale;
    611612# ifdef BYTE_SWAP
    612       SWAP_BYTE;
     613      if (!nativeOrder) { SWAP_BYTE; }
    613614# endif
    614615    } 
     
    619620      *(int *)Pout = (*(double *)Pin - Bzero) / Bscale;
    620621# ifdef BYTE_SWAP
    621       SWAP_WORD;
     622      if (!nativeOrder) { SWAP_WORD; }
    622623# endif
    623624    }
     
    628629      *(int64_t *)Pout = (*(double *)Pin - Bzero) / Bscale;
    629630# ifdef BYTE_SWAP
    630       SWAP_DBLE;
     631      if (!nativeOrder) { SWAP_DBLE; }
    631632# endif
    632633    }
     
    637638      *(float *)Pout = (*(double *)Pin - Bzero) / Bscale;
    638639# ifdef BYTE_SWAP
    639       SWAP_WORD;
     640      if (!nativeOrder) { SWAP_WORD; }
    640641# endif
    641642    }
     
    646647      *(double *)Pout = (*(double *)Pin - Bzero) / Bscale;
    647648# ifdef BYTE_SWAP
    648       SWAP_DBLE;
     649      if (!nativeOrder) { SWAP_DBLE; }
    649650# endif
    650651    }
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c

    r38363 r38366  
    1313# if (VERBOSE_DUMP)
    1414  int i;
    15   fprintf (stderr, "%s data: ", message);
    16   // for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {
    17   for (i = 0; i < 16; i++) {
    18     fprintf (stderr, "0x%02hhx ", table->buffer[i]);
     15  fprintf (stderr, "%s data:\n", message);
     16  for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {
     17    // for (i = 0; i < 16; i++) {
     18    fprintf (stderr, "%02hhx", table->buffer[i]);
     19    if (i % 2) fprintf (stderr, " ");
     20    if (i % 32 == 31) fprintf (stderr, "\n");
    1921  }
    2022  fprintf (stderr, "\n");
     
    2628# if (VERBOSE_DUMP)
    2729  int i;
    28   fprintf (stderr, "%s pntr: ", message);
    29   for (i = 0; (i < 16) && (i < table->header->Naxis[0]*table->header->Naxis[1]); i++) {
    30     fprintf (stderr, "0x%02hhx ", table->buffer[i]);
     30  fprintf (stderr, "%s pntr:\n", message);
     31  for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {
     32    fprintf (stderr, "%02hhx", table->buffer[i]);
     33    if (i % 2) fprintf (stderr, " ");
     34    if (i % 32 == 31) fprintf (stderr, "\n");
    3135  }
    3236  fprintf (stderr, "\n");
    3337
    34   fprintf (stderr, "%s data: ", message);
    35   for (i = 0; (i < 16) && (i < table->header->pcount); i++) {
    36     fprintf (stderr, "0x%02hhx ", table->buffer[table->heap_start + i]);
     38  fprintf (stderr, "%s data:\n", message);
     39  for (i = 0; i < table->header->pcount; i++) {
     40    fprintf (stderr, "%02hhx", table->buffer[table->heap_start + i]);
     41    if (i % 2) fprintf (stderr, " ");
     42    if (i % 32 == 31) fprintf (stderr, "\n");
    3743  }
    3844  fprintf (stderr, "\n");
     
    156162      if (!zdata) ESCAPE;
    157163   
    158       if (strcasecmp(fields[i].zctype, "GZIP_1") && strcasecmp(fields[i].zctype, "GZIP_2") && strcasecmp(fields[i].zctype, "RICE_1")) {
     164      if (VERBOSE_DUMP) {
     165        int k;
     166        fprintf (stderr, "u4: ");
     167        for (k = 0; k < Nzdata; k++) {
     168          fprintf (stderr, "%02hhx", zdata[k]);
     169          if (k % 2) fprintf (stderr, " ");
     170          // if (k % 32 == 31) fprintf (stderr, "\n");
     171        }
     172        fprintf (stderr, "\n");
     173      }
     174
     175      if (strcasecmp(fields[i].zctype, "NONE") &&
     176          strcasecmp(fields[i].zctype, "NONE_2") &&
     177          strcasecmp(fields[i].zctype, "GZIP_1") &&
     178          strcasecmp(fields[i].zctype, "GZIP_2") &&
     179          strcasecmp(fields[i].zctype, "RICE_1") &&
     180          strcasecmp(fields[i].zctype, "RICE_ONE")) {
    159181        // Nzdata is number of bytes
    160182        if (!gfits_byteswap_zdata (zdata, Nzdata, fields[i].pixsize)) ESCAPE;
    161183      }
    162184
     185      if (VERBOSE_DUMP) {
     186        int k;
     187        fprintf (stderr, "u3: ");
     188        for (k = 0; k < Nzdata; k++) {
     189          fprintf (stderr, "%02hhx", zdata[k]);
     190          if (k % 2) fprintf (stderr, " ");
     191          // if (k % 32 == 31) fprintf (stderr, "\n");
     192        }
     193        fprintf (stderr, "\n");
     194      }
     195
    163196      int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen;
    164       int Nraw = Nraw_alloc; // expected number of pixel: Nrows*fields[i].Nvalues
    165       if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE;
     197      int Nraw = Nrows*fields[i].Nvalues*fields[i].pixsize; // expected number of bytes
     198      if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, Nraw_alloc, fields[i].pixsize)) ESCAPE;
     199
     200      if (VERBOSE_DUMP) {
     201        int k;
     202        fprintf (stderr, "u2: ");
     203        for (k = 0; k < Nraw*fields[i].pixsize; k++) {
     204          fprintf (stderr, "%02hhx", raw[k]);
     205          if (k % 2) fprintf (stderr, " ");
     206          // if (k % 32 == 31) fprintf (stderr, "\n");
     207        }
     208        fprintf (stderr, "\n");
     209      }
    166210
    167211      if (!strcasecmp(fields[i].zctype, "GZIP_1")) {
     
    170214      }
    171215
     216      if (VERBOSE_DUMP) {
     217        int k;
     218        fprintf (stderr, "u1: ");
     219        for (k = 0; k < Nraw*fields[i].pixsize; k++) {
     220          fprintf (stderr, "%02hhx", raw[k]);
     221          if (k % 2) fprintf (stderr, " ");
     222          // if (k % 32 == 31) fprintf (stderr, "\n");
     223        }
     224        fprintf (stderr, "\n");
     225      }
     226
    172227      // int valid = (row == 0) && (i == 0);
    173228
     
    177232
    178233      // copy the raw pixels from their native matrix locations to the temporary output buffer
    179       if (!strcasecmp(fields[i].zctype, "GZIP_2")) {
     234      if (!strcasecmp(fields[i].zctype, "GZIP_2") || !strcasecmp(fields[i].zctype, "NONE_2")) {
    180235        if (!gfits_distribute_table_gzp2 (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE;
    181236      } else {
     
    233288    for (i = 0; i < Nrows; i++) {
    234289      int row = row_start + i;
    235       char *src = &raw[i*field->rowsize + k*Nrows*field->Nvalues];
    236       char *tgt = &table->buffer[Nx*row + field->offset + k];
    237       for (j = 0; j < field->Nvalues; j++, tgt+=field->pixsize, src++) {
    238         *tgt = *src;
     290      char *rawptr = &raw[i*field->Nvalues + k*Nrows*field->Nvalues];
     291# ifdef BYTE_SWAP     
     292      char *tblptr = &table->buffer[Nx*row + field->offset + (field->pixsize - k - 1)];
     293# else
     294      char *tblptr = &table->buffer[Nx*row + field->offset + k];
     295# endif
     296      for (j = 0; j < field->Nvalues; j++, tblptr += field->pixsize, rawptr++) {
     297        *tblptr = *rawptr;
    239298      }
    240299    }
  • branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh

    r38363 r38366  
    55  tapPLAN 88
    66
    7   foreach mode NONE GZIP_1 GZIP_2 RICE_1
     7  foreach mode NONE GZIP_1 GZIP_2 RICE_1 RICE_ONE
    88  # foreach mode GZIP_1
    99  # foreach mode GZIP_2
     
    1111    foreach bitpix 8 16 32 -32 -64
    1212    # foreach bitpix 32
    13       if (($mode == RICE_1) && ($bitpix < 0)) continue ; # RICE_1 is for int only
     13      if (($mode == RICE_1)   && ($bitpix < 0)) continue ; # RICE_1 is for int only
     14      if (($mode == RICE_ONE) && ($bitpix < 0)) continue ; # RICE_1 is for int only
    1415      tapDIAG 2 "===== bitpix = $bitpix, mode = $mode ====="
    1516      test_image_single $bitpix $mode
     
    2930 $bitpix = $1
    3031 $cmpmode = $2
     32
     33 delete -q x z b c d e
    3134
    3235 mcreate z 8 8
     
    121124macro test_table_all_single_column
    122125
     126  tapPLAN 88
     127
    123128  local format cmpmode
    124129
    125   foreach cmpmode NONE GZIP_1
     130  foreach cmpmode NONE GZIP_1 GZIP_2 RICE_1 RICE_ONE
    126131    foreach format B I J K E D
     132      if (($cmpmode == RICE_1)   && ($format == E)) continue ; # RICE_1 is for int only
     133      if (($cmpmode == RICE_ONE) && ($format == E)) continue ; # RICE_1 is for int only
     134      if (($cmpmode == RICE_1)   && ($format == D)) continue ; # RICE_1 is for int only
     135      if (($cmpmode == RICE_ONE) && ($format == D)) continue ; # RICE_1 is for int only
     136      if (($cmpmode == RICE_1)   && ($format == K)) continue ; # RICE_1 is for int only
     137      if (($cmpmode == RICE_ONE) && ($format == K)) continue ; # RICE_1 is for int only
    127138      test_table_single_column $cmpmode $format
    128139    end
    129140  end
     141  tapDONE
    130142end
    131143
     
    136148 end
    137149
    138  local cmpmode
     150 local cmpmode format
    139151 $cmpmode = $1
    140 
    141  delete -q x
    142 
    143  $NPT = 1000
    144  create x 0 $NPT
    145 
    146  local format
     152 $format = $2
     153
     154 tapDIAG 2 "===== testing $cmpmode $format ====="
     155
     156 delete -q x dv
     157
     158 $NPT = 10000
     159
     160 if ($format == B)
     161   create x -128 128
     162 else
     163   create x 0 $NPT
     164 end
    147165
    148166 $fields = x
    149  $format = $2
    150167
    151168 write -fits test test.raw.tbl $fields -format $format
     
    157174 end
    158175
    159  echo "===== $cmpmode $format raw ====="
     176 tapDIAG 2 "===== $cmpmode $format raw ====="
    160177 data test.raw.tbl
    161178 read -fits test $fields
     
    163180 foreach f $fields
    164181   set dv = $f - $f\_raw
    165    vstat dv
    166  end
    167  delete -q $fields
    168 
    169  echo "===== $cmpmode $format cmp ====="
     182   vstat -q dv
     183   tapOK {abs($MEAN)  < 0.001} "read our raw $cmpmode $format (MEAN  = $MEAN)"
     184   tapOK {$SIGMA      < 0.001} "read our raw $cmpmode $format (SIGMA = $SIGMA)"
     185 end
     186 delete -q $fields
     187
     188 tapDIAG 2 "===== $cmpmode $format cmp ====="
    170189 data test.cmp.tbl
    171190 read -fits test $fields
     
    173192 foreach f $fields
    174193   set dv = $f - $f\_raw
    175    vstat dv
    176  end
     194   vstat -q dv
     195   tapOK {abs($MEAN)  < 0.001} "read our cmp $cmpmode $format (MEAN  = $MEAN)"
     196   tapOK {$SIGMA      < 0.001} "read our cmp $cmpmode $format (SIGMA = $SIGMA)"
     197 end
     198
     199 if ($cmpmode == NONE) return; # funpack will not recognize NONE
     200 if ($cmpmode == RICE_ONE) return; # funpack will not recognize RICE_ONE for tables
     201 if (($cmpmode == GZIP_2) && ($format == B)) return; # GZIP_2 invalid for B
     202
     203 tapDIAG 2 "===== $cmpmode $format fpack ====="
     204
     205 # try to run fpack on ours
     206 if (1)
     207   tapEXEC /bin/cp -f test.raw.tbl test.fpk.tbl
     208   tapEXEC fpack -table -F test.fpk.tbl
     209   
     210   data test.fpk.tbl
     211   read -fits test $fields
     212   
     213   foreach f $fields
     214     set dv = $f - $f\_raw
     215     vstat -q dv
     216     tapOK {abs($MEAN)  < 0.001} "read fpack $cmpmode $format (MEAN  = $MEAN)"
     217     tapOK {$SIGMA      < 0.001} "read fpack $cmpmode $format (SIGMA = $SIGMA)"
     218   end
     219   delete -q $fields
     220 end
     221
     222 break -auto off
     223 echo $cmpmode $format
     224 exec ls test.cmp.tbl test.fpk.tbl | fields -x 0 PCOUNT  ZCTYP1
     225 break -auto on
     226
     227 tapDIAG 2 "===== $cmpmode $format funpack ====="
     228
     229 # try to run fpack on ours
     230 tapEXEC /bin/cp -f test.cmp.tbl test.fun.tbl
     231 tapEXEC funpack -F test.fun.tbl
     232
     233 data test.fun.tbl
     234 read -fits test $fields
     235
     236 foreach f $fields
     237   set dv = $f - $f\_raw
     238   vstat -q dv
     239   tapOK {abs($MEAN)  < 0.001} "read funpack $cmpmode $format (MEAN  = $MEAN)"
     240   tapOK {$SIGMA      < 0.001} "read funpack $cmpmode $format (SIGMA = $SIGMA)"
     241 end
     242 delete -q $fields
    177243end
    178244
     
    199265 delete -q x y z
    200266
    201  $NPT = 1000
     267 $NPT = 10000
    202268 create x 0 $NPT
    203269 set y = x^2
  • branches/eam_branches/ohana.20150429/src/libfits/test/imagecomp.c

    r38362 r38366  
    55int test_compress (int bitpix, char *zcmptype);
    66
    7 // char *cmptype[] = {"NONE", "GZIP_1", "GZIP_2", "PLIO_1", "RICE_1", "RICE_ONE", "HCOMPRESS_1", NULL};
    8 // char *cmptype[] = {"NONE", "GZIP_1", "RICE_1", "RICE_ONE", NULL};
    9 // int bitpix[] = {8, 16, 32, -32, -64, 0};
    10 
    11 // char *cmptype[] = {"NONE", "GZIP_1", NULL};
    12 // char *cmptype[] = {"PLIO_1", NULL};
    13 // int bitpix[] = {8, 16, 32, 0};
    14 
    15 char *cmptype[] = {"GZIP_2", NULL};
    16 int bitpix[] = {-32, 0};
     7// char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "PLIO_1", "RICE_1", "RICE_ONE", "HCOMPRESS_1", NULL};
     8char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "RICE_1", "RICE_ONE", NULL};
     9int bitpix[] = {8, 16, 32, -32, -64, 0};
    1710
    1811int main (int argc, char **argv) {
     
    2518  for (i = 0; cmptype[i]; i++) {
    2619    for (j = 0; bitpix[j]; j++) {
     20      if (!strcasecmp (cmptype[i], "RICE_1") && (bitpix[j] < 0)) continue;
     21      if (!strcasecmp (cmptype[i], "RICE_ONE") && (bitpix[j] < 0)) continue;
    2722      test_compress (bitpix[j], cmptype[i]);
    2823    }
    2924  }
    30 
    31   // test_compress ( 16, "NONE");
    32   // test_compress ( 32, "NONE");
    33   // test_compress (-32, "NONE");
    34   // test_compress (-64, "NONE");
    35   //
    36   // test_compress (  8, "GZIP_1");
    37   // test_compress ( 16, "GZIP_1");
    38   // test_compress ( 32, "GZIP_1");
    39   // test_compress (-32, "GZIP_1");
    40   // test_compress (-64, "GZIP_1");
    41 
    4225  exit (0);
    4326}
  • branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c

    r38363 r38366  
    44
    55int test_compress (char *zcmptype);
     6int test_compress_single_full (char *zcmptype);
    67
    78int main (int argc, char **argv) {
     
    1011
    1112  diag ("libfits tablecomp.c tests");
     13
     14  test_compress_single_full ("GZIP_1");
     15  test_compress_single_full ("RICE_1");
    1216
    1317  test_compress (NULL);
    1418  test_compress ("NONE");
     19  test_compress ("NONE_2");
    1520  test_compress ("GZIP_1");
    1621  test_compress ("GZIP_2");
    17   // test_compress ("GZIP_1");
     22  test_compress ("RICE_1");
     23  test_compress ("RICE_ONE");
    1824
    1925  exit (0);
     
    3137  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
    3238
     39  ok (gfits_define_bintable_column (&header, "B", "VAL", "val", "none", 1.0, 0.0), "defined byte column");
    3340  ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
    3441  ok (gfits_define_bintable_column (&header, "J", "ID",  "ID", "none", 1.0, 0.0),  "defined int column");
     
    4047
    4148  int Nval = 1000;
     49  char  *VAL;  ALLOCATE (VAL, char,   Nval);
    4250  short *SEQ;  ALLOCATE (SEQ, short,  Nval);
    4351  int    *ID;  ALLOCATE (ID,  int,    Nval);
     
    4755  int i;
    4856  for (i = 0; i < Nval; i++) {
     57    VAL[i] = i + 32;
    4958    SEQ[i] = i;
    5059    ID[i] = 10000*i + 100*i;
     
    5463
    5564  // add the columns to the output array
     65  ok (gfits_set_bintable_column (&header, &ftable, "VAL", VAL, Nval), "set byte   table column");
    5666  ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
    5767  ok (gfits_set_bintable_column (&header, &ftable,  "ID",  ID, Nval), "set int    table column");
     
    8494  off_t Nrow;
    8595
     96  char   *VAL_t = gfits_get_bintable_column_data (outheader, outtable, "VAL", type, &Nrow, &Ncol); ok (!strcmp (type, "byte"),   "read byte   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    8697  short  *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"),  "read short  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    8798  int     *ID_t = gfits_get_bintable_column_data (outheader, outtable,  "ID", type, &Nrow, &Ncol); ok (!strcmp (type, "int"),    "read int    table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     
    90101
    91102  // count mismatched values
     103  int Nvalue = 0;
    92104  int Nseq = 0;
    93105  int  Nid = 0;
     
    95107  int   Ny = 0;
    96108  for (i = 0; i < Nval; i++) {
     109    if (VAL[i] != VAL_t[i]) Nvalue++;
    97110    if (SEQ[i] != SEQ_t[i]) Nseq++;
    98111    if ( ID[i] !=  ID_t[i]) Nid++;
     
    101114  }
    102115
    103   ok (!Nseq, "short  values match (input vs output)");
    104   ok (!Nid,  "int    values match (input vs output)");
    105   ok (!Nx,   "float  values match (input vs output)");
    106   ok (!Ny,   "double values match (input vs output)");
     116  ok (!Nvalue, "byte   values match (input vs output)");
     117  ok (!Nseq,   "short  values match (input vs output)");
     118  ok (!Nid,    "int    values match (input vs output)");
     119  ok (!Nx,     "float  values match (input vs output)");
     120  ok (!Ny,     "double values match (input vs output)");
    107121
    108122  gfits_free_header (&header);
     
    115129}
    116130
     131int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
     132
     133  Header header;
     134  FTable ftable;
     135
     136  diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
     137  ok (gfits_init_header (&header), "inited the header");
     138  ok (gfits_init_table (&ftable), "inited the table");
     139
     140  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
     141
     142  ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
     143 
     144  // generate the output array that carries the data
     145  ok (gfits_create_table (&header, &ftable), "created the basic table");
     146
     147  int Nval = 1000;
     148  short *SEQ;  ALLOCATE (SEQ, short,  Nval);
     149 
     150  int i;
     151  for (i = 0; i < Nval; i++) {
     152    SEQ[i] = i;
     153  }     
     154
     155  // add the columns to the output array
     156  ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
     157
     158  Header *outheader = &header;
     159  FTable *outtable = &ftable;
     160
     161  if (zcmptype) {
     162    Header cmpheader;
     163    FTable cmptable;
     164    cmptable.header = &cmpheader;
     165    ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
     166
     167    Header rawheader;
     168    FTable rawtable;
     169    rawtable.header = &rawheader;
     170    ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
     171   
     172    gfits_free_header (&cmpheader);
     173    gfits_free_table (&cmptable);
     174
     175    outheader = &rawheader;
     176    outtable  = &rawtable;
     177  }
     178
     179  char type[16];
     180  int Ncol;
     181  off_t Nrow;
     182
     183  short  *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"),  "read short  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     184
     185  // count mismatched values
     186  int Nseq = 0;
     187  for (i = 0; i < Nval; i++) {
     188    if (SEQ[i] != SEQ_t[i]) Nseq++;
     189  }
     190
     191  ok (!Nseq,   "short  values match (input vs output)");
     192
     193  gfits_free_header (&header);
     194  gfits_free_table (&ftable);
     195  if (zcmptype) {
     196    gfits_free_header (outheader);
     197    gfits_free_table (outtable);
     198  }
     199  return TRUE;
     200}
     201
Note: See TracChangeset for help on using the changeset viewer.