IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38334


Ignore:
Timestamp:
May 29, 2015, 5:24:53 PM (11 years ago)
Author:
eugene
Message:

table compression is internally consistent (tables can be generated and compressed)

Location:
branches/eam_branches/ohana.20150429/src/libfits
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/Makefile

    r38329 r38334  
    1313INC     =       $(HOME)/include
    1414MAN     =       $(HOME)/doc
     15TEST    =       $(HOME)/test
     16TESTBIN =       $(HOME)/test
    1517include ../../Makefile.Common
    1618
     
    1921FULL_CPPFLAGS = $(BASE_CPPFLAGS) -I$(EXT)
    2022FULL_LDFLAGS  = $(BASE_LDFLAGS) -lohana
     23
     24TEST_CFLAGS   = $(BASE_CFLAGS)
     25TEST_CPPFLAGS = $(BASE_CPPFLAGS)
     26TEST_LDFLAGS  = $(BASE_LDFLAGS) -lFITS -lohana -ltap_ohana
     27
     28TESTPROG = tablecomp zlib
     29$(TESTPROG) : % : $(TESTBIN)/%
     30test: $(TESTPROG)
    2131
    2232install: $(DESTLIB)/libFITS.a $(DESTLIB)/libFITS.$(DLLTYPE) $(DESTMAN)/fits.1
  • branches/eam_branches/ohana.20150429/src/libfits/extern/gzip.c

    r38329 r38334  
    120120{
    121121    z_stream stream;
    122     int err;
     122    int i, err;
    123123
    124124    stream.next_in = (Bytef*)source;
     
    135135    stream.opaque = Z_NULL;
    136136
     137    if (0) {
     138      fprintf (stderr, "inp unc: ");
     139      for (i = 0; i < sourceLen; i++) {
     140        fprintf (stderr, "0x%02hhx ", source[i]);
     141      }
     142      fprintf (stderr, "\n");
     143    }
     144
    137145    // err = inflateInit2(&stream, -15);
    138146    err = inflateInit(&stream);
     147    if (0) fprintf (stderr, "inp buffers unc 0: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);
     148
    139149    if (err != Z_OK) return err;
    140150
    141151    err = inflate(&stream, Z_FINISH);
     152    if (0) fprintf (stderr, "out buffers unc 1: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);
    142153    if (err != Z_STREAM_END) {
    143154        inflateEnd(&stream);
    144         if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
    145             return Z_DATA_ERROR;
     155        if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) return Z_DATA_ERROR;
    146156        return err;
    147157    }
     158    if (0) fprintf (stderr, "out buffers unc 2: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);
     159
     160    if (0) {
     161      fprintf (stderr, "out unc: ");
     162      for (i = 0; i < stream.total_out; i++) {
     163        fprintf (stderr, "0x%02hhx ", dest[i]);
     164      }
     165      fprintf (stderr, "\n");
     166    }
     167
    148168    assert (stream.total_out <= *destLen);
    149169    *destLen = stream.total_out;
     
    156176{
    157177  z_stream stream;
    158   int err;
     178  int i, err;
    159179 
    160180  stream.next_in = (Bytef*)source;
     
    172192  stream.opaque = Z_NULL;
    173193
     194  if (0) {
     195    fprintf (stderr, "inp cmp: ");
     196    for (i = 0; i < sourceLen; i++) {
     197      fprintf (stderr, "0x%02hhx ", source[i]);
     198    }
     199    fprintf (stderr, "\n");
     200  }
     201
    174202  // the '5' is the compression level: make this a user argument
    175203  err = deflateInit(&stream, 5);
     204  if (0) fprintf (stderr, "inp buffers cmp 0: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);
     205
    176206  if (err != Z_OK) return err;
    177207
     
    179209  // the compression occur in a series of steps
    180210  err = deflate(&stream, Z_FINISH);
     211  if (0) fprintf (stderr, "out buffers cmp 1: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);
     212
    181213  if (err != Z_STREAM_END) {
    182     deflateEnd(&stream);
    183     return err;
    184   }
     214    err = deflateEnd(&stream);
     215    return Z_BUF_ERROR;
     216  }
     217  if (0) fprintf (stderr, "out buffers cmp 2: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);
     218
     219  if (0) {
     220    fprintf (stderr, "out cmp: ");
     221    for (i = 0; i < stream.total_out; i++) {
     222      fprintf (stderr, "0x%02hhx ", dest[i]);
     223    }
     224    fprintf (stderr, "\n");
     225  }
     226
    185227  assert (stream.total_out <= *destLen);
    186228  *destLen = stream.total_out;
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_data.c

    r38329 r38334  
    2727int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
    2828
    29 static int pass = 0;
    30 
    3129int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype,
    3230                         char **optname, char **optvalue, int Nopt,
     
    3432
    3533  int status;
     34
     35  // do not actually compress : this is used for testing
     36  if (!strcasecmp(cmptype, "NONE")) {
     37    unsigned long Nbytes = Nrawpix * rawpix_size;
     38
     39    memcpy (zdata, rawdata, Nbytes);
     40    *Nzdata = Nbytes;
     41    return (TRUE);
     42  }
    3643
    3744  if (!strcasecmp(cmptype, "GZIP_1")) {
     
    4956      fprintf (stderr, "error in compress (GZIP)\n");
    5057      return (FALSE);
    51     }
    52 
    53     // test of deflate (vs I/O)
    54     {
    55       char *srcbuf, *tgtbuf;
    56       ALLOCATE (srcbuf, char, destLen);
    57       memcpy (srcbuf, zdata, destLen);
    58 
    59       ALLOCATE (tgtbuf, char, Nbytes);
    60      
    61       uLongf Ndeflate = Nbytes;
    62       status = gfits_uncompress ((Bytef *) tgtbuf, &Ndeflate, (Bytef *) zdata, destLen);
    63       if (status != Z_OK) {
    64         fprintf (stderr, "error in uncompress (GZIP) : %d vs %d\n", status, Z_OK);
    65         return (FALSE);
    66       }
    67      
    68       myAssert (Ndeflate == Nbytes, "invalid output size?");
    69 
    70       int i;
    71       for (i = 0; i < Ndeflate; i++) {
    72         myAssert (rawdata[i] == tgtbuf[i], "data mismatch?");
    73       }
    74 
    75     }
    76 
    77     if (pass == 0) {
    78       int i;
    79       for (i = 0; i < 32; i++) {
    80         fprintf (stderr, "0x%02hhx ", zdata[i]);
    81       }
    82       fprintf (stderr, "\n");
    83       pass = 1;
    8458    }
    8559    return (TRUE);
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c

    r38329 r38334  
    197197
    198198  // find the COMPRESSED_DATA column (format should be 1PB, 1PI, 1PJ)
     199  // is it required that this be the only column?
    199200  for (i = 1; TRUE; i++) {
    200201    snprintf (key, 10, "TTYPE%d", i);
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_data.c

    r38329 r38334  
    2626int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
    2727
    28 static int pass = 0;
    29 
    3028int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize) {
    3129
     
    3331  static int Ninsum = 0;
    3432  static int Noutsum = 0;
     33
     34  // do not actually uncompress : this is used for testing
     35  if (!strcasecmp(cmptype, "NONE")) {
     36    memcpy (outdata, zdata, Nzdata);
     37    *Nout = Nzdata / out_pixsize;
     38    return (TRUE);
     39  }
    3540
    3641  if (!strcasecmp(cmptype, "GZIP_1")) {
     
    4045    // XXX maybe not anymore
    4146    // gfits_gz_stripheader ((unsigned char *)zdata, &Nzdata);
    42 
    43     if (pass == 0) {
    44       int i;
    45       for (i = 0; i < 32; i++) {
    46         fprintf (stderr, "0x%02hhx ", zdata[i]);
    47       }
    48       fprintf (stderr, "\n");
    49       pass = 1;
    50     }
    5147
    5248    // uncompress does not require us to know the expected number of pixel; it tells us the number
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c

    r38329 r38334  
    5656
    5757  TableField *fields = NULL;
    58   ALLOCATE (fields, TableField, Nfields);
     58  ALLOCATE_ZERO (fields, TableField, Nfields);
    5959  for (i = 0; i < Nfields; i++) {
    6060    snprintf (keyword, 80, "TTYPE%d", i+1);
     
    129129
    130130    fields[i].offset = offset;
    131     offset += fields[i].offset;
     131    offset += fields[i].rowsize;
    132132  }
    133133
    134134  // allocate the intermediate storage buffers
     135  int Nzdata_alloc = max_width*ztilelen + 100;
    135136  ALLOCATE (raw,   char, max_width*ztilelen);
    136   ALLOCATE (zdata, char, max_width*ztilelen);
     137  ALLOCATE (zdata, char, Nzdata_alloc);
    137138
    138139  // compress the data : copy into a tile, compress the tile, then add to the output table
     
    153154     
    154155      int Nraw = Nrows*fields[j].Nvalues; // number of pixels
    155       int Nzdata = max_width*ztilelen; // available space, replaced with actual output size on compression
     156      int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression
    156157      if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize)) ESCAPE(A);
    157158     
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_table_varlength.c

    r38329 r38334  
    128128  Nx = ftable->header->Naxis[0];
    129129
    130 # ifdef BYTE_SWAP
    131   char *pchar, tmp;
    132   pchar = &ftable->buffer[row*Nx + column->offset];
    133   SWAP_WORD;
    134   pchar = &ftable->buffer[row*Nx + column->offset + 4];
    135   SWAP_WORD;
    136 # endif
    137 
    138130  if (column->mode == 'P') {
    139131    int *ptr;
     
    156148// for varlength columns to the heap.  To start, assume we have defined the cartesian
    157149// portion of the table correctly, and are only extending the heap.
    158 
    159 // XXX NOTE: this function assumes the table data is currently in local byte swap order.
    160 // swap before writing out
    161150
    162151int gfits_varlength_column_add_data (FTable *table, char *data, off_t Ndata, int row, VarLengthColumn *column) {
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c

    r38329 r38334  
    6868
    6969    fields[i].offset = offset;
    70     offset += fields[i].offset;
     70    offset += fields[i].rowsize;
    7171
    7272    if (!gfits_varlength_column_define (srctable, &fields[i].zdef, i + 1)) ESCAPE(A);
Note: See TracChangeset for help on using the changeset viewer.