IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38363


Ignore:
Timestamp:
Jun 4, 2015, 8:49:25 AM (11 years ago)
Author:
eugene
Message:

rice and gzip2 both work for images; working on tables

Location:
branches/eam_branches/ohana.20150429/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c

    r38362 r38363  
    173173
    174174  // size of a pixel in the image tile -- this is probably not needed
    175   // int tile_pixsize = abs(header[0].bitpix) / 8;
    176   // fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix);
     175# if VERBOSE_DUMP
     176  int tile_pixsize = abs(header[0].bitpix) / 8;
     177  fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix);
     178# endif
    177179
    178180  // allocate the buffer for compression work
     
    210212
    211213    // gzip compresses bytes which are in BIG-ENDIAN order
     214    // Nraw is number of pixels
    212215    if (!strcasecmp(zcmptype, "GZIP_1")) {
    213       // Nraw is number of pixels
    214216      if (!gfits_byteswap_zdata (raw, Nraw * raw_pixsize, raw_pixsize)) ESCAPE;
    215217    }
     
    238240    // compression modes require swapping after compression (compresssion & decompression
    239241    // operate on native ENDIAN)
    240     if (strcasecmp(zcmptype, "GZIP_1") && strcasecmp(zcmptype, "GZIP_2")) {
     242    if (strcasecmp(zcmptype, "GZIP_1") && strcasecmp(zcmptype, "GZIP_2") && strcasecmp(zcmptype, "RICE_1")) {
    241243      // Nzdata is number of bytes
    242244      if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c

    r38362 r38363  
    284284    }
    285285
    286     if (strcasecmp(cmptype, "GZIP_1")) {
     286    if (strcasecmp(cmptype, "GZIP_1") && strcasecmp(cmptype, "GZIP_2") && strcasecmp(cmptype, "RICE_1")) {
    287287      // Nzdata is number of bytes
    288288      if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c

    r38356 r38363  
    1818// we do not try to support compression of an image with an associated table (not valid)
    1919
    20 # define ESCAPE(A) { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
    21 
    22 int gfits_collect_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize);
     20# define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
     21
     22int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
     23int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
    2324
    2425int gfits_compress_table (FTable *srctable, FTable *tgttable, int ztilelen, char *zcmptype) {
     
    5051
    5152  // creates an empty (Naxes = 2, Naxis[i] = 0) table header with XTENSION = BINTABLE, EXTNAME = COMPRESSED_TABLE
    52   if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE(A);
     53  if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE;
    5354
    5455  int Nfields;
    55   if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE(A);
     56  if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE;
    5657
    5758  TableField *fields = NULL;
     
    5960  for (i = 0; i < Nfields; i++) {
    6061    snprintf (keyword, 80, "TTYPE%d", i+1);
    61     if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE(A);
    62     if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE(A);
     62    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE;
     63    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE;
    6364
    6465    // TUNIT is not mandatory
     
    6768      fields[i].tunit[0] = 0;
    6869    } else {
    69       if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE(A);
     70      if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE;
    7071    }
    7172   
    7273    snprintf (keyword, 80, "TFORM%d", i+1);
    73     if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE(A);
    74     if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE(A);
     74    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE;
     75    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE;
    7576
    7677    // XXX this should depend on the field type, but for now just use a single type (GZIP_1)
     
    7879
    7980    // by using "P" format, we are limited to 32bit pointers (2GB heap)
    80     if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE (A);
     81    if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE;
    8182  }   
    8283
    8384  // allocates the default data array (tgttable->buffer)
    84   if (!gfits_create_table (tgtheader, tgttable)) ESCAPE (A);
     85  if (!gfits_create_table (tgtheader, tgttable)) ESCAPE;
    8586
    8687  // copy original header to output header (XXX this needs to be finished)
    87   if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE (A);
     88  if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE;
    8889 
    8990  // this allocates the pointer data array for the full set of tiles (NOT the heap)
     
    9192  ALLOCATE_ZERO (tmpbuffer, char, 16*Ntile); // need space for Ntile entries, each of width 16 bytes (2 long)
    9293  for (i = 0; i < Nfields; i++) {
    93     if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ntile)) ESCAPE (A);
     94    if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ntile)) ESCAPE;
    9495  }
    9596  free (tmpbuffer);
    9697   
    9798  // add ZIMAGE from output header
    98   if (!gfits_modify_alt (tgtheader, "ZTABLE", "%t", 1, TRUE)) ESCAPE (A);
     99  if (!gfits_modify_alt (tgtheader, "ZTABLE", "%t", 1, TRUE)) ESCAPE;
    99100
    100101  // define compression-specific keywords, update header as needed.
    101   if (!gfits_modify (tgtheader, "ZTILELEN", "%d", 1, ztilelen)) ESCAPE(A);
    102 
    103   if (!gfits_modify (tgtheader, "ZNAXIS1", OFF_T_FMT, 1, srcheader->Naxis[0])) ESCAPE (A);
    104   if (!gfits_modify (tgtheader, "ZNAXIS2", OFF_T_FMT, 1, srcheader->Naxis[1])) ESCAPE (A);
     102  if (!gfits_modify (tgtheader, "ZTILELEN", "%d", 1, ztilelen)) ESCAPE;
     103
     104  if (!gfits_modify (tgtheader, "ZNAXIS1", OFF_T_FMT, 1, srcheader->Naxis[0])) ESCAPE;
     105  if (!gfits_modify (tgtheader, "ZNAXIS2", OFF_T_FMT, 1, srcheader->Naxis[1])) ESCAPE;
    105106
    106107  off_t pcount;
    107   if (!gfits_scan (srcheader, "PCOUNT", OFF_T_FMT, 1, &pcount)) ESCAPE (A);
    108   if (!gfits_modify (tgtheader, "ZPCOUNT", OFF_T_FMT, 1, pcount)) ESCAPE (A);
     108  if (!gfits_scan (srcheader, "PCOUNT", OFF_T_FMT, 1, &pcount)) ESCAPE;
     109  if (!gfits_modify (tgtheader, "ZPCOUNT", OFF_T_FMT, 1, pcount)) ESCAPE;
    109110
    110111  off_t theap;
    111112  if (gfits_scan (srcheader, "THEAP", OFF_T_FMT, 1, &theap)) {
    112     if (!gfits_modify (tgtheader, "ZTHEAP", OFF_T_FMT, 1, theap)) ESCAPE (A);
     113    if (!gfits_modify (tgtheader, "ZTHEAP", OFF_T_FMT, 1, theap)) ESCAPE;
    113114  }
    114115 
     
    118119  for (i = 0; i < Nfields; i++) {
    119120    snprintf (keyword, 81, "ZFORM%d", i+1);
    120     if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE (A);
    121     if (!gfits_varlength_column_define (tgttable, &fields[i].zdef, i+1)) ESCAPE(A);
    122     if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE(A); //
     121    if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE;
     122    if (!gfits_varlength_column_define (tgttable, &fields[i].zdef, i+1)) ESCAPE;
     123    if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE; //
    123124    fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize;
    124125    max_width = MAX(max_width, fields[i].rowsize);
     
    126127    // compression type per column (XXX for now we are just using zcmptype, as set above)
    127128    snprintf (keyword, 81, "ZCTYP%d", i+1);
    128     if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].zctype)) ESCAPE (A);
     129    if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].zctype)) ESCAPE;
    129130
    130131    fields[i].offset = offset;
     
    151152
    152153      // copy the raw pixels from their native matrix locations to the temporary output buffer
    153       if (!gfits_collect_table_data (srctable, raw, fields[j].offset, row_start, Nrows, fields[j].rowsize)) ESCAPE(A);
     154      if (!strcasecmp(fields[i].zctype, "GZIP_2")) {
     155        if (!gfits_collect_table_gzp2 (srctable, &fields[j], raw, row_start, Nrows)) ESCAPE;
     156      } else {
     157        if (!gfits_collect_table_data (srctable, &fields[j], raw, row_start, Nrows)) ESCAPE;
     158      }
    154159     
    155160      // optname, optvalue = NULL, Noptions = 0
     
    157162      int Nraw = Nrows*fields[j].Nvalues; // number of pixels
    158163      if (!strcmp(fields[j].zctype, "GZIP_1")) {
    159         if (!gfits_byteswap_zdata (raw, Nraw * fields[j].pixsize, fields[j].pixsize)) ESCAPE(A);
     164        if (!gfits_byteswap_zdata (raw, Nraw * fields[j].pixsize, fields[j].pixsize)) ESCAPE;
    160165      }
    161166
    162167      int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression
    163       if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE(A);
     168      if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE;
    164169     
    165       if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, i, &fields[j].zdef)) ESCAPE(A);
    166      
    167       // XXX need to activate
    168       // if (FALSE) gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize) ESCAPE(A);
     170      if (strcasecmp(fields[j].zctype, "GZIP_1") && strcasecmp(fields[j].zctype, "GZIP_2") && strcasecmp(fields[j].zctype, "RICE_1")) {
     171        if (!gfits_byteswap_zdata (zdata, Nzdata, fields[j].pixsize)) ESCAPE;
     172      }
     173
     174      if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, i, &fields[j].zdef)) ESCAPE;
    169175    }
    170176  }
    171177
    172178  for (i = 0; i < Nfields; i++) {
    173     if (!gfits_varlength_column_finish (tgttable, &fields[i].zdef)) ESCAPE(A);
     179    if (!gfits_varlength_column_finish (tgttable, &fields[i].zdef)) ESCAPE;
    174180  }
    175181
     
    190196// raw_pixsize is the bytes / pixel for the input matrix
    191197// place the raw image bytes for the current tile into the tile buffer
    192 int gfits_collect_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize) {
     198int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
    193199
    194200  off_t i;
     
    201207  for (i = 0; i < Nrows; i++) {
    202208    int row = row_start + i;
    203     memcpy (&raw[i*rowsize], &table->buffer[Nx*row + col], rowsize);
     209    memcpy (&raw[i*field->rowsize], &table->buffer[Nx*row + field->offset], field->rowsize);
    204210# if (VERBOSE)
    205     int j; for (j = 0; j < rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + col + j]);
     211    int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]);
    206212# endif
    207213  }
     
    210216  return (TRUE);
    211217}
     218
     219int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
     220
     221  off_t i, j, k;
     222
     223  // we are copying NN rows into the column which starts at XX and has MM bytes per row
     224
     225  off_t Nx = table->header->Naxis[0];
     226
     227  for (k = 0; k < field->pixsize; k++) {
     228    for (i = 0; i < Nrows; i++) {
     229      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->
     235      }
     236    }
     237  }
     238  return (TRUE);
     239}
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c

    r38356 r38363  
    33# include <zlib.h>
    44
    5 # define ESCAPE(A) { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
    6 
    7 int gfits_distribute_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize);
     5# define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
     6
     7int gfits_distribute_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
     8int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows);
    89
    910# define VERBOSE_DUMP 0
     
    5354
    5455  int ztilelen;
    55   if (!gfits_scan (srcheader, "ZTILELEN", "%d", 1, &ztilelen)) ESCAPE(A);
     56  if (!gfits_scan (srcheader, "ZTILELEN", "%d", 1, &ztilelen)) ESCAPE;
    5657  // XXX if ZTILELEN is missing, it should have the value of ZNAXIS2
    5758
     
    6364
    6465  // creates an empty (Naxes = 2, Naxis[i] = 0) table header with XTENSION = BINTABLE, EXTNAME = COMPRESSED_TABLE
    65   if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE(A);
     66  if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE;
    6667
    6768  int Nfields;
    68   if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE(A);
     69  if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE;
    6970
    7071  // below we generate a fake table with tmpbuffers.  allocated it to the max needed size
     
    7677  for (i = 0; i < Nfields; i++) {
    7778    snprintf (keyword, 80, "TTYPE%d", i+1);
    78     if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE(A);
    79     if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE(A);
     79    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE;
     80    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE;
    8081
    8182    // TUNIT is not mandatory
     
    8485      fields[i].tunit[0] = 0;
    8586    } else {
    86       if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE(A);
     87      if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE;
    8788    }
    8889   
    8990    snprintf (keyword, 80, "ZFORM%d", i+1);
    90     if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE(A);
    91     if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE(A);
     91    if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE;
     92    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE;
    9293
    9394    snprintf (keyword, 80, "ZCTYP%d", i+1);
     
    9697    }
    9798
    98     if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE(A);
     99    if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE;
    99100    fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize;
    100101    max_width = MAX(max_width, fields[i].rowsize);
     
    103104    offset += fields[i].rowsize;
    104105
    105     if (!gfits_varlength_column_define (srctable, &fields[i].zdef, i + 1)) ESCAPE(A);
    106 
    107     if (!gfits_define_bintable_column (tgtheader, fields[i].tformat, fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE (A);
     106    if (!gfits_varlength_column_define (srctable, &fields[i].zdef, i + 1)) ESCAPE;
     107
     108    if (!gfits_define_bintable_column (tgtheader, fields[i].tformat, fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE;
    108109  }   
    109110
    110111  // allocates the default data array (tgttable->buffer)
    111   if (!gfits_create_table (tgtheader, tgttable)) ESCAPE (A);
     112  if (!gfits_create_table (tgtheader, tgttable)) ESCAPE;
    112113
    113114  // copy original header to output header (XXX this needs to be finished)
    114   if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE (A);
     115  if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE;
    115116 
    116117  off_t Nx, Ny;
    117   if (!gfits_scan (srcheader, "ZNAXIS1", OFF_T_FMT, 1, &Nx)) ESCAPE (A);
    118   if (!gfits_scan (srcheader, "ZNAXIS2", OFF_T_FMT, 1, &Ny)) ESCAPE (A);
     118  if (!gfits_scan (srcheader, "ZNAXIS1", OFF_T_FMT, 1, &Nx)) ESCAPE;
     119  if (!gfits_scan (srcheader, "ZNAXIS2", OFF_T_FMT, 1, &Ny)) ESCAPE;
    119120  myAssert (Nx == tgtheader->Naxis[0], "table definition error?");
    120121
     
    123124  ALLOCATE_ZERO (tmpbuffer, char, max_width*Ny);
    124125  for (i = 0; i < Nfields; i++) {
    125     if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ny)) ESCAPE (A);
     126    if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ny)) ESCAPE;
    126127  }
    127128  free (tmpbuffer);
     
    153154      off_t Nzdata;
    154155      char *zdata = gfits_varlength_column_pointer (srctable, &fields[i].zdef, row, &Nzdata);
    155       if (!zdata) ESCAPE(A);
     156      if (!zdata) ESCAPE;
    156157   
     158      if (strcasecmp(fields[i].zctype, "GZIP_1") && strcasecmp(fields[i].zctype, "GZIP_2") && strcasecmp(fields[i].zctype, "RICE_1")) {
     159        // Nzdata is number of bytes
     160        if (!gfits_byteswap_zdata (zdata, Nzdata, fields[i].pixsize)) ESCAPE;
     161      }
     162
    157163      int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen;
    158164      int Nraw = Nraw_alloc; // expected number of pixel: Nrows*fields[i].Nvalues
    159       if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE(A);
     165      if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE;
    160166
    161167      if (!strcasecmp(fields[i].zctype, "GZIP_1")) {
    162168        myAssert ((fields[i].zdef.format != 'C') && (fields[i].zdef.format != 'M'), "swap is probably wrong for C or M columns");
    163         if (!gfits_byteswap_zdata (raw, Nraw * fields[i].pixsize, fields[i].pixsize)) ESCAPE(A);
     169        if (!gfits_byteswap_zdata (raw, Nraw * fields[i].pixsize, fields[i].pixsize)) ESCAPE;
    164170      }
    165171
     
    171177
    172178      // copy the raw pixels from their native matrix locations to the temporary output buffer
    173       if (!gfits_distribute_table_data (tgttable, raw, fields[i].offset, row_start, Nrows, fields[i].rowsize)) ESCAPE(A);
    174      
    175       // XXX need to activate
    176       // if (FALSE) gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize) ESCAPE(A);
     179      if (!strcasecmp(fields[i].zctype, "GZIP_2")) {
     180        if (!gfits_distribute_table_gzp2 (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE;
     181      } else {
     182        if (!gfits_distribute_table_data (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE;
     183      }     
    177184    }
    178185  }
     
    194201// raw_pixsize is the bytes / pixel for the input matrix
    195202// place the raw image bytes for the current tile into the tile buffer
    196 int gfits_distribute_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize) {
     203int gfits_distribute_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
    197204
    198205  off_t i;
     
    202209  off_t Nx = table->header->Naxis[0];
    203210
    204   if (VERBOSE) fprintf (stderr, "collect: ");
     211  if (VERBOSE) fprintf (stderr, "distribute: ");
    205212  for (i = 0; i < Nrows; i++) {
    206213    int row = row_start + i;
    207     memcpy (&table->buffer[Nx*row + col], &raw[i*rowsize], rowsize);
     214    memcpy (&table->buffer[Nx*row + field->offset], &raw[i*field->rowsize], field->rowsize);
    208215# if (VERBOSE)
    209     int j; for (j = 0; j < rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + col + j]);
     216    int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]);
    210217# endif
    211218  }
     
    214221  return (TRUE);
    215222}
     223
     224int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) {
     225
     226  off_t i, j, k;
     227
     228  // we are copying NN rows into the column which starts at XX and has MM bytes per row
     229
     230  off_t Nx = table->header->Naxis[0];
     231
     232  for (k = 0; k < field->pixsize; k++) {
     233    for (i = 0; i < Nrows; i++) {
     234      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;
     239      }
     240    }
     241  }
     242  return (TRUE);
     243}
  • branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh

    r38362 r38363  
     1input tap.dvo
    12
    23macro test_image_all
    34
    4   # foreach mode NONE GZIP_1 RICE_1
     5  tapPLAN 88
     6
     7  foreach mode NONE GZIP_1 GZIP_2 RICE_1
    58  # foreach mode GZIP_1
    6   foreach mode GZIP_2
     9  # foreach mode GZIP_2
    710  # foreach mode RICE_1
    811    foreach bitpix 8 16 32 -32 -64
    912    # foreach bitpix 32
    10       echo ===== bitpix = $bitpix =====
     13      if (($mode == RICE_1) && ($bitpix < 0)) continue ; # RICE_1 is for int only
     14      tapDIAG 2 "===== bitpix = $bitpix, mode = $mode ====="
    1115      test_image_single $bitpix $mode
    1216    end
    1317  end
     18
     19  tapDONE
    1420end
    1521
     
    3036 rd b test.cmp.fits -x 0
    3137 set d = x - b
    32  stat d
     38 stat -q d
     39 tapOK {abs($MEAN)  < 0.001} "read our cmp $cmpmode $bitpix (MEAN  = $MEAN)"
     40 tapOK {$SIGMA      < 0.001} "read our cmp $cmpmode $bitpix (SIGMA = $SIGMA)"
    3341
    3442 if ($cmpmode == NONE) return
     
    4351   exec fpack -r -S test.raw.fits > test.fpk.fits
    4452 end
    45  echo "load fpack version"
     53 # echo "load fpack version"
    4654 rd c test.fpk.fits -x 0
    4755 set d = x - c
    48  stat d
     56 stat -q d
     57 tapOK {abs($MEAN)  < 0.001} "read fpack $cmpmode $bitpix (MEAN  = $MEAN)"
     58 tapOK {$SIGMA      < 0.001} "read fpack $cmpmode $bitpix (SIGMA = $SIGMA)"
    4959
    5060 if ($cmpmode == RICE_1_0)
     
    5363 end
    5464
    55  echo "run funpack on our version"
     65 # echo "run funpack on our version"
    5666 exec funpack -S test.cmp.fits > test.fun.fits
    5767 rd e test.fun.fits
    5868 set d = x - e
    59  stat d
     69 stat -q d
     70 tapOK {abs($MEAN)  < 0.001} "funpack our cmp $cmpmode $bitpix (MEAN  = $MEAN)"
     71 tapOK {$SIGMA      < 0.001} "funpack our cmp $cmpmode $bitpix (SIGMA = $SIGMA)"
    6072end
    6173
  • branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c

    r38340 r38363  
    1414  test_compress ("NONE");
    1515  test_compress ("GZIP_1");
     16  test_compress ("GZIP_2");
     17  // test_compress ("GZIP_1");
    1618
    1719  exit (0);
  • branches/eam_branches/ohana.20150429/src/opihi/cmd.data/rd.c

    r38340 r38363  
    88  char region[512];
    99  Buffer *buf;
     10
     11  int VERBOSE = FALSE;
     12  if ((N = get_argument (argc, argv, "-v"))) {
     13    remove_argument (N, &argc, argv);
     14    VERBOSE = TRUE;
     15  }
    1016
    1117  int JustHead = FALSE;
     
    193199    gfits_copy_header (&buf[0].header, ftable.header);
    194200
    195     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { fprintf (stderr, "problem reading compressed image table data\n"); fclose (f); return FALSE; }
    196     if (!gfits_byteswap_varlength_column (&ftable, 1)) { fprintf (stderr, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
    197     if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { fprintf (stderr, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
     201    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { gprint (GP_ERR, "problem reading compressed image table data\n"); fclose (f); return FALSE; }
     202    if (!gfits_byteswap_varlength_column (&ftable, 1)) { gprint (GP_ERR, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
     203    if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { gprint (GP_ERR, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
    198204
    199205    // uncompressing the image leaves the format as an extension
     
    238244  buf[0].unsign = buf[0].header.unsign;
    239245
    240   gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n",
    241            buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
     246  if (VERBOSE) gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
    242247
    243248  blank = 0xffff;
Note: See TracChangeset for help on using the changeset viewer.