IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41474


Ignore:
Timestamp:
Jan 24, 2021, 3:37:52 PM (5 years ago)
Author:
eugene
Message:

clarify in comments the buffers and pixel sizes used in the different stages of compression/uncompression; catch unimplemented compression cases; fix error in pixel size for RICE1; cleanup verbose code; use correct sscanf format code in ASCII table reading code

Location:
trunk/Ohana/src/libfits
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r41433 r41474  
    214214int     gfits_byteswap_zdata            PROTO((char *zdata, off_t Nzdata, int pixsize));
    215215int     gfits_compressed_data_pixsize   PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
    216 int     gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
    217 int     gfits_uncompressed_data_bitpix  PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
     216int     gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions, int rice_use_bitpix));
     217int     gfits_uncompressed_data_bitpix  PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions, int rice_use_bitpix));
    218218int     gfits_vartable_heap_pixsize     PROTO((char format));
    219219int     gfits_cmptype_valid             PROTO((char *cmptype));
  • trunk/Ohana/src/libfits/matrix/F_compress_M.c

    r39457 r41474  
    7676  if (!gfits_modify (theader, "ZCMPTYPE", "%s", 1, zcmptype)) ESCAPE;
    7777
    78   // define compression-specific keywords, update header as needed.
    79   if (!strcasecmp(zcmptype, "GZIP_1") || !strcasecmp(zcmptype, "GZIP_2")) {
    80     if ((header[0].bitpix == -32) || (header[0].bitpix == -64)) {
    81       if (!gfits_modify (theader, "ZQUANTIZ", "%s", 1, "NONE")) ESCAPE;
    82     }
    83   }
    84 
    8578  if (!gfits_modify_alt (theader, "ZSIMPLE", "%t", 1, TRUE)) ESCAPE;
    8679  // gfits_modify (header, "ZTENSION", "%s", 1, exttype);
     
    124117  int oblank = 32767;
    125118  // gfits_modify (header, "BLANK", "%d", 1, oblank);
     119
     120  // define compression-specific keywords, update header as needed.
     121  if (!strcasecmp(zcmptype, "GZIP_1") || !strcasecmp(zcmptype, "GZIP_2")) {
     122    if ((header[0].bitpix == -32) || (header[0].bitpix == -64)) {
     123      if (!gfits_modify (theader, "ZQUANTIZ", "%s", 1, "NONE")) ESCAPE;
     124    }
     125  }
    126126
    127127# if (0)
     
    159159  unsigned long int max_tile_size = gfits_imtile_maxsize (matrix, ztile);
    160160
    161   // size of a pixel in the raw pixel buffer (before compression)
    162   int raw_pixsize = gfits_uncompressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0);
    163   int raw_bitpix  = gfits_uncompressed_data_bitpix (zcmptype, header[0].bitpix, NULL, NULL, 0);
     161  // size of a pixel in the compressed data (cmp_pixsize), used for byteswap below
    164162  int cmp_pixsize = gfits_compressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0);
     163
     164  // size of a pixel in the raw pixel buffer (before compression) (last option says RICE uses header.bitpix)
     165  int raw_pixsize = gfits_uncompressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0, TRUE);
     166
     167  // we also need the bitpix value for the raw uncompressed buffer to distinguish int and floats
     168  int raw_bitpix  = gfits_uncompressed_data_bitpix (zcmptype, header[0].bitpix, NULL, NULL, 0, TRUE);
    165169
    166170  // define compression-specific keywords, update header as needed.
     
    237241    }
    238242
    239     // GZIP_1 is swapped before compression; GZIP_2 implies swapping.  All other
    240     // compression modes require swapping after compression (compresssion & decompression
    241     // operate on native ENDIAN)
    242     if (strcasecmp(zcmptype, "NONE_2") && // strcasecmp(zcmptype, "NONE") &&
    243         strcasecmp(zcmptype, "GZIP_1") &&
    244         strcasecmp(zcmptype, "GZIP_2") &&
    245         strcasecmp(zcmptype, "RICE_1") &&
    246         strcasecmp(zcmptype, "RICE_ONE")) {
    247       // Nzdata is number of bytes
    248       if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
    249     }
     243    // BYTESWAP the compressed data after compressing.  Compression algorithms which do
     244    // not need to byteswap here return 1 for cmp_pixsize.  GZIP_1 is swapped before
     245    // compression; GZIP_2 implies swapping.  All other compression modes require swapping
     246    // after compression (the compresssion & decompression functions operate on native
     247    // ENDIAN data values).
     248    if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
    250249
    251250    if (VERBOSE_DUMP && (i == 0)) {
  • trunk/Ohana/src/libfits/matrix/F_compress_data.c

    r39457 r41474  
    120120
    121121    if (status) {
    122       fprintf (stderr, "error in hdecompress\n");
     122      fprintf (stderr, "error in hcompress\n");
    123123      return (FALSE);
    124124    }
  • trunk/Ohana/src/libfits/matrix/F_compress_utils.c

    r39457 r41474  
    104104  // fprintf (stderr, "swapping %d bytes in pix of size %d bytes...\n", Nzdata, pixsize);
    105105  switch (pixsize) {
     106    case 0:
    106107    case 1:
    107108      break;
     
    186187}
    187188
    188 int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
     189// the size of the compressed data pixels, needed to perform swaps
     190int gfits_compressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
     191
     192  // NONE should be swapped to mimic swapping types
     193  if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1")) {
     194    if (out_bitpix ==   8) return (1);
     195    if (out_bitpix ==  16) return (2);
     196    if (out_bitpix ==  32) return (4);
     197    if (out_bitpix == -32) return (4);
     198    if (out_bitpix == -64) return (8);
     199    return (1);
     200  }
     201
     202  // GZIP_1, GZIP_2 should not be swapped after compression / before decompression
     203  if (!strcasecmp(cmptype, "GZIP_1") ||
     204      !strcasecmp(cmptype, "GZIP_2") ||
     205      !strcasecmp(cmptype, "NONE_2")) {
     206    if (out_bitpix ==   8) return (1);
     207    if (out_bitpix ==  16) return (1);
     208    if (out_bitpix ==  32) return (1);
     209    if (out_bitpix == -32) return (1);
     210    if (out_bitpix == -64) return (1);
     211    return (1);
     212  }
     213
     214  // RICE_1 should not be swapped after compression / before decompression
     215  if (!strcasecmp(cmptype, "RICE_1") ||
     216      !strcasecmp(cmptype, "RICE_ONE")) {
     217    return (1);
     218  }
     219
     220  // PLIO_1 always results in 4-byte ints (not 2 byte ints?)
     221  if (!strcasecmp(cmptype, "PLIO_1")) {
     222    return (4);
     223  }
     224
     225  if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
     226    if (out_bitpix == 8)  return (4);
     227    if (out_bitpix == 16) return (4);
     228    return (8);
     229  }
     230  return (0);
     231}
     232
     233int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions, int rice_use_bitpix) {
    189234
    190235  int i, Nbyte;
     
    207252  if (!strcasecmp(cmptype, "RICE_1") ||
    208253      !strcasecmp(cmptype, "RICE_ONE")) {
     254    // on compression, user may set BYTEPIX based on header.bitpix:
     255    if (rice_use_bitpix) {
     256      if (out_bitpix ==   8) return (1);
     257      if (out_bitpix ==  16) return (2);
     258      if (out_bitpix ==  32) return (4);
     259    }
    209260    // if BYTEPIX option is specified, use that for Nbyte
    210261    for (i = 0; i < Noptions; i++) {
     
    214265      }
    215266    }
    216     if (out_bitpix ==   8) return (1);
    217     if (out_bitpix ==  16) return (2);
    218     if (out_bitpix ==  32) return (4);
    219     return (4);
     267    return (4); // RICE_1 default is 4 byte int if BYTEPIX undefined (White et al 6.2)
    220268  }
    221269
     
    233281}
    234282
    235 int gfits_compressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
    236 
    237   int i, Nbyte;
    238 
    239   // NONE should be swapped to mimic swapping types
    240   if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1")) {
    241     if (out_bitpix ==   8) return (1);
    242     if (out_bitpix ==  16) return (2);
    243     if (out_bitpix ==  32) return (4);
    244     if (out_bitpix == -32) return (4);
    245     if (out_bitpix == -64) return (8);
    246     return (1);
    247   }
    248 
    249   // GZIP_1, GZIP_2 should not be swapped after compression
    250   if (!strcasecmp(cmptype, "GZIP_1") ||
    251       !strcasecmp(cmptype, "GZIP_2") ||
    252       !strcasecmp(cmptype, "NONE_2")) {
    253     if (out_bitpix ==   8) return (1);
    254     if (out_bitpix ==  16) return (1);
    255     if (out_bitpix ==  32) return (1);
    256     if (out_bitpix == -32) return (1);
    257     if (out_bitpix == -64) return (1);
    258     return (1);
    259   }
    260 
    261   // RICE_1 must operate on integer pixels
    262   if (!strcasecmp(cmptype, "RICE_1") ||
    263       !strcasecmp(cmptype, "RICE_ONE")) {
    264     // if BYTEPIX option is specified, use that for Nbyte
    265     for (i = 0; i < Noptions; i++) {
    266       if (!strcmp(optname[i], "BYTEPIX")) {
    267         Nbyte = atoi (optvalue[i]);
    268         return (Nbyte);
    269       }
    270     }
    271     if (out_bitpix ==   8) return (1);
    272     if (out_bitpix ==  16) return (2);
    273     if (out_bitpix ==  32) return (4);
    274     return (4);
    275   }
    276 
    277   // PLIO_1 always results in 4-byte ints (not 2 byte ints?)
    278   if (!strcasecmp(cmptype, "PLIO_1")) {
    279     return (4);
    280   }
    281 
    282   if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
    283     if (out_bitpix == 8)  return (4);
    284     if (out_bitpix == 16) return (4);
    285     return (8);
    286   }
    287   return (0);
    288 }
    289 
    290 int gfits_uncompressed_data_bitpix (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
     283int gfits_uncompressed_data_bitpix (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions, int rice_use_bitpix) {
    291284
    292285  int i, Nbyte;
     
    304297  if (!strcasecmp(cmptype, "RICE_1") ||
    305298      !strcasecmp(cmptype, "RICE_ONE")) {
     299    if (rice_use_bitpix) {
     300      if (out_bitpix ==   8) return (out_bitpix);
     301      if (out_bitpix ==  16) return (out_bitpix);
     302      if (out_bitpix ==  32) return (out_bitpix);
     303    }
    306304    // if BYTEPIX option is specified, use that for Nbyte
    307305    for (i = 0; i < Noptions; i++) {
     
    311309      }
    312310    }
    313     if (out_bitpix ==   8) return (out_bitpix);
    314     if (out_bitpix ==  16) return (out_bitpix);
    315     if (out_bitpix ==  32) return (out_bitpix);
    316311    return (32);
    317312  }
  • trunk/Ohana/src/libfits/matrix/F_uncompress_M.c

    r40549 r41474  
    4040    gfits_modify (header, NAME, TYPE, 1, OUT); }
    4141
     42# define DUMP_ROWBYTES(BUF, INFO)              \
     43  if (VERBOSE_DUMP && (row == 0)) {            \
     44    int k;                                     \
     45    fprintf (stderr, "%s: ", INFO);            \
     46    for (k = 0; k < 64; k++) {                 \
     47      fprintf (stderr, "%02hhx", BUF[k]);    \
     48      if (k % 4 == 3) fprintf (stderr, " ");   \
     49    } fprintf (stderr, "\n"); }
     50
    4251int gfits_uncompress_image (Header *header, Matrix *matrix, FTable *ftable) {
    4352
     
    97106  } else {
    98107    gfits_delete (header, "ZTILE1", 1);
     108    // if ZTILE1 exists, all ZTILEn must exist:
    99109    for (axis = 1; axis < header->Naxes; axis++) {
    100110      snprintf (key, 10, "ZTILE%d", axis + 1);
     
    127137  }
    128138
    129   // XXX get ZMASKCMP
    130   int zsimple, have_zsimple;
    131   int have_ztension;
     139  // check for ZMASKCMP (not yet supported 2021.01.23)
     140  char zmaskcmp[81];
     141  int have_zmaskcmp = gfits_scan (header, "ZMASKCMP", "%s", 1, zmaskcmp);
     142  if (have_zmaskcmp) {
     143    fprintf (stderr, "null pixels were compressed with %s, not implemented in Ohana\n", zmaskcmp);
     144    ESCAPE;
     145  }
    132146
    133147  // NOTE target of %t must be int length
    134   have_zsimple  = gfits_scan_alt (header, "ZSIMPLE", "%t", 1, &zsimple);
    135   have_ztension = gfits_scan (header, "ZTENSION", "%s", 1, exttype);
    136 
    137   // this is a very bogus case: we cannot have both keywords
     148  int zsimple;
     149  int have_zsimple  = gfits_scan_alt (header, "ZSIMPLE", "%t", 1, &zsimple);
     150  int have_ztension = gfits_scan (header, "ZTENSION", "%s", 1, exttype);
     151
     152  // this is a bogus case: we cannot have both keywords
    138153  if (have_zsimple && have_ztension) ESCAPE;
    139154
     
    179194    }
    180195  } else {
     196    // if this is a PHU (whether or not ZSIMPLE is present), PCOUNT & GCOUNT must be basic (0,1)
    181197    header->pcount = 0;
    182198    header->gcount = 1;
     
    188204  MOD_KEYWORD ("ZDATASUM", "DATASUM",  "%s", datasum,         datasum);
    189205
    190   zscale = 1;
    191   gfits_scan (header, "ZSCALE", "%f", 1, &zscale);
    192 
    193   zblank = 32767;
    194   gfits_scan (header, "ZBLANK", "%d", 1, &zblank);
    195 
    196   oblank = 32767;
    197   gfits_scan (header, "BLANK", "%d", 1, &oblank);
    198 
    199   zzero = 0;
    200   gfits_scan (header, "ZZERO", "%f", 1, &zzero);
     206  // get other basic keywords (default values supplied)
     207  zscale = 1;      gfits_scan (header, "ZSCALE", "%f", 1, &zscale);
     208  zblank = 32767;  gfits_scan (header, "ZBLANK", "%d", 1, &zblank);
     209  oblank = 32767;  gfits_scan (header, "BLANK", "%d", 1, &oblank);
     210  zzero = 0;       gfits_scan (header, "ZZERO", "%f", 1, &zzero);
    201211
    202212  // find the COMPRESSED_DATA column (format should be 1PB, 1PI, 1PJ)
    203   // is it required that this be the only column?
     213  // XXX is it required that this be the only column? -- not if ZMASKCMP exists (not yet supported)
    204214  int colnum;
    205215  for (colnum = 1; TRUE; colnum++) {
     
    242252
    243253  // heapdata.pixsize : zdef.format
    244   // zdata.pixsize : depends on compression
    245   // odata.pixsize : depends on compression
    246   // idata.pixsize : header.bitpix
     254  // zdata.pixsize : depends on compression method (cmp_pixsize below)
     255  // odata.pixsize : depends on compression method (raw_pixsize below)
     256  // idata.pixsize : depends on header.bitpix
    247257
    248258  // size of an element in the vartable heap section
    249259  // zdata_pixsize = gfits_vartable_heap_pixsize (zdef.format); XXX
    250260
    251   // size of a pixel in the output from the decompression routine
     261  // depending on the compression method, the data may need to be byteswapped either before
     262  // or after uncompression:
     263
     264  // size of a pixel in the compressed data (cmp_pixsize), used for byteswap below
    252265  int cmp_pixsize = gfits_compressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions);
    253   int raw_bitpix  = gfits_uncompressed_data_bitpix (cmptype, header[0].bitpix, optname, optvalue, Noptions);
    254   int raw_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions);
     266
     267  // size of a pixel in the raw uncomprssed buffer (raw_pixsize) after uncompression (last option says RICE ignores bitpix)
     268  int raw_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions, FALSE);
     269
     270  // we also need the bitpix value for the raw uncompressed buffer to distinguish int and floats
     271  int raw_bitpix  = gfits_uncompressed_data_bitpix (cmptype, header[0].bitpix, optname, optvalue, Noptions, FALSE);
    255272
    256273  // size of a pixel in the final image (not needed)
     
    261278  ALLOCATE (out, char, Nout_alloc);
    262279
    263   off_t row;
    264 
    265   if (VERBOSE_DUMP) {
    266     int k;
    267     fprintf (stderr, "unc tbl: ");
    268     for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", ftable->buffer[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    269     fprintf (stderr, "\n");
    270   }
    271 
    272280  // uncompress the data
    273281  Nzrows = ftable->header->Naxis[1];
    274   for (row = 0; row < Nzrows; row++) {
     282  for (off_t row = 0; row < Nzrows; row++) {
     283
     284    DUMP_ROWBYTES (ftable->buffer, "tbl dat");
    275285
    276286    // expected output size for this tile
     
    280290    if (!zdata) ESCAPE;
    281291
    282     if (VERBOSE_DUMP && (row == 0)) {
    283       int k;
    284       fprintf (stderr, "unc dat: ");
    285       for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    286       fprintf (stderr, "\n");
    287     }
    288 
    289     if (strcasecmp(cmptype, "NONE_2") && // strcasecmp(cmptype, "NONE") &&
    290         strcasecmp(cmptype, "GZIP_1") &&
    291         strcasecmp(cmptype, "GZIP_2") &&
    292         strcasecmp(cmptype, "RICE_1") &&
    293         strcasecmp(cmptype, "RICE_ONE")) {
    294       // Nzdata is number of bytes
    295       if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
    296     }
    297 
    298     if (VERBOSE_DUMP && (row == 0)) {
    299       int k;
    300       fprintf (stderr, "unc SWP: ");
    301       for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    302       fprintf (stderr, "\n");
    303       fprintf (stderr, "Nout  : %lu -> ", Nout);
    304     }
     292    DUMP_ROWBYTES (zdata, "cmp dat");
     293
     294    // byteswap the compressed data before uncompressing.
     295    // compression algorithms which do not need to byteswap here return 1 for cmp_pixsize
     296    if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
     297
     298    DUMP_ROWBYTES (zdata, "cmp swp");
    305299   
    306300    // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated
    307     // XXX the tile must not be > 2GB
    308     // Nout going in is number of bytes
     301    // Note: the tile must not be > 2GB
     302    // Nout going in is the expected number of bytes
    309303    if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, Nout_alloc, raw_pixsize)) ESCAPE;
    310304
    311     if (VERBOSE_DUMP && (row == 0)) {
    312       int k;
    313       fprintf (stderr, "%lu\n", Nout);
    314       fprintf (stderr, "unc swp: ");
    315       for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", out[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    316       fprintf (stderr, "\n");
    317     }
     305    DUMP_ROWBYTES (out, "unc swp");
    318306   
    319307    if (!strcasecmp(cmptype, "GZIP_1")) {
     
    322310    }
    323311   
    324     if (VERBOSE_DUMP && (row == 0)) {
    325       int k;
    326       fprintf (stderr, "unc raw: ");
    327       for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", out[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    328       fprintf (stderr, "\n");
    329     }
     312    DUMP_ROWBYTES (out, "unc raw");
    330313
    331314    // copy the uncompressed pixels into their correct locations           
     
    336319    }
    337320
    338     if (VERBOSE_DUMP && (row == 0)) {
    339       int k;
    340       fprintf (stderr, "unc mat: ");
    341       for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", matrix->buffer[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    342       fprintf (stderr, "\n");
    343     }
     321    DUMP_ROWBYTES (matrix->buffer, "out raw");
    344322
    345323    // update the tile counters, carrying to the next dimension if needed
     
    370348}
    371349
    372 // bitpix is the input data size/type
     350// raw_bitpix is the data size/type for the temporary buffer of uncompressed data
     351// matrix->bitpix is the data size/type of the output image data
    373352int gfits_distribute_data (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) {
    374353
     
    514493}
    515494
    516 // bitpix is the input data size/type
     495// raw_bitpix is the data size/type for the temporary buffer of uncompressed data
     496// matrix->bitpix is the data size/type of the output image data
     497// The gzip2 algorithm organizes the compressed data in groups by significant byte sequence (most significant byte of all pixels first, etc).
     498// gfits_distribute_gzp2 needs to shuffle the bytes back into the correct location in the tile.
    517499int gfits_distribute_gzp2 (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) {
     500  // unused parameters are supplied to make this function have the same API as gfits_distribute_data()
    518501  OHANA_UNUSED_PARAM(oblank);
    519502  OHANA_UNUSED_PARAM(zblank);
  • trunk/Ohana/src/libfits/matrix/F_uncompress_data.c

    r39457 r41474  
    55
    66# define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
     7
     8/* This function uncompresses the data in 'zdata' into the pre-allocated output buffer 'outdata'.
     9   The compression algorithm is chosen based on 'cmptype', with options specified by 'optname, optvalue, Nopt'
     10   zdata : input compressed data, Nzdata : number of compressed BYTES
     11   outdata : output buffer, Nout : number of actual output PIXELS, Nout_alloc : number of allocated bytes in the buffer, out_pixsize : bytes per output pixel
     12 */
    713
    814int gfits_uncompress_data (char *zdata, unsigned long Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, unsigned long int *Nout, unsigned long int Nout_alloc, int out_pixsize) {
  • trunk/Ohana/src/libfits/table/F_get_column.c

    r41433 r41474  
    403403  if (!strcmp (type, "int")) {
    404404    ALLOCATE (array, char, Ny*4);
    405     Pout = array;
    406     for (i = 0; i < Ny; i++, Pin+=Nx, Pout+=4) {
     405    int *tmpPtr = (int *)array;
     406    for (i = 0; i < Ny; i++, Pin+=Nx, tmpPtr ++) {
    407407      memcpy (line, Pin, Nval*Nbytes);
    408       sscanf (line, cformat, (int *)Pout);
     408      sscanf (line, "%d", tmpPtr);
     409      // fprintf (stderr, "test: %d %d\n", Nscan, tmpValue);
    409410    }
    410411  }
    411412  if (!strcmp (type, "int64_t")) {
    412413    ALLOCATE (array, char, Ny*8);
    413     Pout = array;
    414     for (i = 0; i < Ny; i++, Pin+=Nx, Pout+=8) {
     414    int64_t *tmpPtr = (int64_t *)array;
     415    for (i = 0; i < Ny; i++, Pin+=Nx, tmpPtr ++) {
    415416      memcpy (line, Pin, Nval*Nbytes);
    416       sscanf (line, "%" PRId64, (int64_t *)Pout);
     417      sscanf (line, "%" PRId64, tmpPtr);
    417418    }
    418419  }
    419420  if (!strcmp (type, "float")) {
    420421    ALLOCATE (array, char, Ny*4);
    421     Pout = array;
    422     for (i = 0; i < Ny; i++, Pin+=Nx, Pout+=4) {
     422    float *tmpPtr = (float *) array;
     423    for (i = 0; i < Ny; i++, Pin+=Nx, tmpPtr ++) {
    423424      memcpy (line, Pin, Nval*Nbytes);
    424       sscanf (line, cformat, (float *)Pout);
     425      sscanf (line, "%e", tmpPtr);
     426    }
     427  }
     428  if (!strcmp (type, "double")) {
     429    ALLOCATE (array, char, Ny*8);
     430    double *tmpPtr = (double *) array;
     431    for (i = 0; i < Ny; i++, Pin+=Nx, tmpPtr++) {
     432      memcpy (line, Pin, Nval*Nbytes);
     433      sscanf (line, "%le", tmpPtr);
    425434    }
    426435  }
  • trunk/Ohana/src/libfits/table/F_table_format.c

    r41433 r41474  
    9292int gfits_table_format (char *format, char *type, int *Nval, int *Nbytes) {
    9393
    94   char Fchar, Size[80], Type;
     94  char Fchar, Size[80];
    9595  int Nv;
    9696
     
    107107  }
    108108 
    109   Type = 'x';
    110   if (Fchar == 'D') { *Nbytes = 1;  strcpy (type, "double"); Type = 'e'; *Nval = Nv; }
     109  int isLong = FALSE;
     110  char Type = 'x';
     111  if (Fchar == 'D') { *Nbytes = 1;  strcpy (type, "double"); Type = 'e'; *Nval = Nv; isLong = TRUE; }
    111112  if (Fchar == 'E') { *Nbytes = 1;  strcpy (type, "float");  Type = 'e'; *Nval = Nv; }
    112113  if (Fchar == 'F') { *Nbytes = 1;  strcpy (type, "float");  Type = 'f'; *Nval = Nv; }
     
    115116  if (!*Nbytes) { return (FALSE); }
    116117 
    117   sprintf (format, "%%-%s%c", Size, Type); // NOTE: this line is not used
     118  if (0) {
     119    // this format is appropriate for scanning, but not printing
     120    if (isLong) {
     121      sprintf (format, "%%%sl%c", Size, Type);
     122    } else {
     123      sprintf (format, "%%%s%c", Size, Type);
     124    }
     125  }
     126 
     127  // this format is appropriate for printing, but not scanning
     128  sprintf (format, "%%-%s%c", Size, Type);
    118129
    119130  return (TRUE);
  • trunk/Ohana/src/libfits/test/compress.sh

    r38425 r41474  
    11input tap.dvo
     2
     3## NOTE: in order to run this test suite, you must have a modern version of fpack / funpack.
     4## The IPP version included in the build tree (3100-p5) does not have support for gzip2 in fpack.
     5
     6## Acceptable versions can be obtained by downloading a current copy
     7## of CFITSIO (https://heasarc.gsfc.nasa.gov/fitsio/).
     8
     9## To avoid installing the library or funpack/fpack in your psconfig
     10## tree, only build the code locally and do NOT install. 
     11
     12## in the cfitsio directory, edit the Makefile with the following changes:
     13
     14## LDFLAGS_BIN =        -g -O2 -Wl,-rpath,${CFITSIO_LIB} -static
     15## CFLAGS =     -g -Dg77Fortran -fPIC
     16## (comment out the old versions)
     17
     18## run psconfigure, make, make fpack funpack
     19
     20## after building these (static) binaries, link them into this test directory
    221
    322macro tests
     
    524  test_table_all_rnd
    625end
     26
     27$FPACK = ./fpack
     28$FUNPACK = ./funpack
    729
    830macro test_image_all
     
    5375
    5476 if ($cmpmode == GZIP_1)
    55    exec fpack -q 0 -g -S test.raw.fits > test.fpk.fits
     77   ## mana does not (yet) handle non-zero quantization
     78   exec $FPACK -q 0 -g -S test.raw.fits > test.fpk.fits
    5679 end
    5780 if ($cmpmode == GZIP_2)
    58    exec fpack -q 0 -g2 -S test.raw.fits > test.fpk.fits
     81   exec $FPACK -q 0 -g2 -S test.raw.fits > test.fpk.fits
    5982 end
    6083 if ($cmpmode == RICE_1)
    61    exec fpack -r -S test.raw.fits > test.fpk.fits
     84   exec $FPACK -r -S test.raw.fits > test.fpk.fits
    6285 end
    6386 # echo "load fpack version"
     
    6891 tapOK {$SIGMA      < 0.001} "read fpack $cmpmode $bitpix (SIGMA = $SIGMA)"
    6992
    70  if ($cmpmode == RICE_1_0)
    71    echo "*** funpack fails on RICE_1 ****"
    72    return
    73  end
     93 # if ($cmpmode == RICE_1_0)
     94 #   echo "*** funpack fails on RICE_1 ****"
     95 #   return
     96 # end
    7497
    7598 # echo "run funpack on our version"
    76  exec funpack -S test.cmp.fits > test.fun.fits
     99 exec $FUNPACK -S test.cmp.fits > test.fun.fits
    77100 rd e test.fun.fits
    78101 set d = x - e
     
    213236 if (1)
    214237   tapEXEC /bin/cp -f test.raw.tbl test.fpk.tbl
    215    tapEXEC fpack -table -F test.fpk.tbl
     238   tapEXEC $FPACK -table -F test.fpk.tbl
    216239   
    217240   data test.fpk.tbl
     
    236259 # try to run fpack on ours
    237260 tapEXEC /bin/cp -f test.cmp.tbl test.fun.tbl
    238  tapEXEC funpack -F test.fun.tbl
     261 tapEXEC $FUNPACK -F test.fun.tbl
    239262
    240263 data test.fun.tbl
     
    403426 if (1)
    404427   tapEXEC /bin/cp -f test.raw.tbl test.fpk.tbl
    405    tapEXEC fpack -table -F test.fpk.tbl
     428   tapEXEC $FPACK -table -F test.fpk.tbl
    406429   
    407430   data test.fpk.tbl
     
    431454 # try to run fpack on ours
    432455 tapEXEC /bin/cp -f test.cmp.tbl test.fun.tbl
    433  tapEXEC funpack -F test.fun.tbl
     456 tapEXEC $FUNPACK -F test.fun.tbl
    434457
    435458 data test.fun.tbl
  • trunk/Ohana/src/libfits/test/imagecomp.c

    r39457 r41474  
    33# include "tap_ohana.h"
    44
     5# define MEM_VERBOSE FALSE
     6
    57int test_compress (int bitpix, char *zcmptype);
    68int test_compress_fullrange (int bitpix, char *zcmptype);
    79int test_compress_fulltile (int bitpix, char *zcmptype);
    810
    9 // char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "PLIO_1", "RICE_1", "RICE_ONE", "HCOMPRESS_1", NULL};
     11// XXX FULL SET : char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "PLIO_1", "RICE_1", "RICE_ONE", "HCOMPRESS_1", NULL};
    1012char *cmptype[] = {"NONE", "NONE_1", "NONE_2", "GZIP_1", "GZIP_2", "RICE_1", "RICE_ONE", NULL};
     13// XXX NOT WORKING: char *cmptype[] = {"HCOMPRESS_1", NULL};
    1114int bitpix[] = {8, 16, 32, -32, -64, 0};
    1215
     
    3134      test_compress_fulltile (bitpix[j], cmptype[i]);
    3235      test_compress_fullrange (bitpix[j], cmptype[i]);
    33       ok (ohana_memcheck (TRUE), "no memory corruption");
     36      ok (ohana_memcheck (MEM_VERBOSE), "no memory corruption");
    3437    }
    3538  }
     
    4346      test_compress_fulltile (bitpix[j], cmptype[i]);
    4447      test_compress_fullrange (bitpix[j], cmptype[i]);
    45       ok (ohana_memcheck (TRUE), "no memory corruption");
     48      ok (ohana_memcheck (MEM_VERBOSE), "no memory corruption");
    4649    }
    4750  }
     
    5558      test_compress_fulltile (bitpix[j], cmptype[i]);
    5659      test_compress_fullrange (bitpix[j], cmptype[i]);
    57       ok (ohana_memcheck (TRUE), "no memory corruption");
     60      ok (ohana_memcheck (MEM_VERBOSE), "no memory corruption");
    5861    }
    5962  }
     
    138141  }     
    139142 
     143  // diag ("--- Image has a total of %d pixels of which %d are bad ---", NX*NY, Nbad);
    140144  ok (!Nbad, "all image pixels match");
    141145
Note: See TracChangeset for help on using the changeset viewer.