IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

libfits compressed I/O seems to be generally working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.