IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38399


Ignore:
Timestamp:
Jun 5, 2015, 7:58:50 PM (11 years ago)
Author:
eugene
Message:

handle zzero,zscale = 0,1 specially to avoid bitlevel errors

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

Legend:

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

    r38366 r38399  
    204204      int k;
    205205      fprintf (stderr, "cmp mat: ");
    206       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", matrix->buffer[k]); }
     206      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", matrix->buffer[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    207207      fprintf (stderr, "\n");
    208208      fprintf (stderr, "cmp raw: ");
    209       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", raw[k]); }
     209      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", raw[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    210210      fprintf (stderr, "\n");
    211211    }
     
    221221      int k;
    222222      fprintf (stderr, "cmp swp: ");
    223       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", raw[k]); }
     223      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", raw[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    224224      fprintf (stderr, "\n");
    225225      fprintf (stderr, "Nzdata: %d -> ", Nzdata);
     
    233233      fprintf (stderr, "%d\n", Nzdata);
    234234      fprintf (stderr, "cmp SWP: ");
    235       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     235      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    236236      fprintf (stderr, "\n");
    237237    }
     
    240240    // compression modes require swapping after compression (compresssion & decompression
    241241    // operate on native ENDIAN)
    242     if (strcasecmp(zcmptype, "NONE") &&
    243         strcasecmp(zcmptype, "NONE_2") &&
     242    if (strcasecmp(zcmptype, "NONE_2") && // strcasecmp(zcmptype, "NONE") &&
    244243        strcasecmp(zcmptype, "GZIP_1") &&
    245244        strcasecmp(zcmptype, "GZIP_2") &&
     
    253252      int k;
    254253      fprintf (stderr, "cmp dat: ");
    255       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     254      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    256255      fprintf (stderr, "\n");
    257256    }
     
    266265    int k;
    267266    fprintf (stderr, "cmp tbl: ");
    268     for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", ftable->buffer[k]); }
     267    for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", ftable->buffer[k]);  if (k % 4 == 3) fprintf (stderr, " "); }
    269268    fprintf (stderr, "\n");
    270269  }
     
    339338  offset = 0;
    340339
     340  int directCopy = (zzero == 0.0) && (zscale == 1.0);
     341
    341342  // we need to set up switches for all of the possible combinations:
    342343  // this macro is used at the inner switch to run the actual loop
    343 # define SCALE_AND_DIST_INT(TYPE, SIZE) {                               \
     344# define SCALE_AND_DIST_INT_PRINT(TYPE, SIZE, INTYPE) {                 \
    344345    TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)];    \
    345346    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
     
    347348        *RAWptr = zblank;                                               \
    348349      } else {                                                          \
    349         *RAWptr = (*TILEptr - zzero) / zscale;                          \
     350        /* *RAWptr = directCopy ? *TILEptr : (*TILEptr - zzero) / zscale; */ \
     351        *RAWptr = *TILEptr;     \
     352        fprintf (stderr, "col: %s to %s : %08x : %08x\n", #TYPE, #INTYPE, *TILEptr, *RAWptr); \
    350353      } } }
    351354
    352355  // we need to set up switches for all of the possible combinations:
    353356  // this macro is used at the inner switch to run the actual loop
    354 # define SCALE_AND_DIST_FLOAT(TYPE, SIZE) {                             \
    355     TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)];    \
     357# define SCALE_AND_DIST_INT(OTYPE, OSIZE) {                             \
     358    OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \
     359    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
     360      if (*TILEptr == oblank) {                                         \
     361        *RAWptr = zblank;                                               \
     362      } else {                                                          \
     363        if (directCopy) {                                               \
     364          *RAWptr = *TILEptr;                                           \
     365        } else {                                                        \
     366          *RAWptr = (*TILEptr - zzero) / zscale;                        \
     367        } } } }
     368
     369  // we need to set up switches for all of the possible combinations:
     370  // this macro is used at the inner switch to run the actual loop
     371# define SCALE_AND_DIST_FLOAT(OTYPE, OSIZE) {                           \
     372    OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \
    356373    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
    357374      if (!isfinite(*TILEptr)) {                                        \
    358375        *RAWptr = zblank;                                               \
    359376      } else {                                                          \
    360         *RAWptr = (*TILEptr - zzero) / zscale;                          \
    361       } } }
     377        if (directCopy) {                                               \
     378          *RAWptr = *TILEptr;                                           \
     379        } else {                                                        \
     380          *RAWptr = (*TILEptr - zzero) / zscale;                        \
     381        } } } }
    362382
    363383  // this macro sets up the outer switch and calls above the macro with all RAW buffer bitpix options
    364384  //
    365 # define SETUP_RAWSIZE(TYPE, SIZE) {                    \
     385# define SETUP_RAWSIZE_PRINT(TYPE, SIZE) {                      \
    366386    TYPE *RAWptr = (TYPE *) &raw[i*SIZE*Ztile[0]];      \
     387    switch (matrix->bitpix) {                           \
     388      case   8: SCALE_AND_DIST_INT   (char,   1); break;        \
     389      case  16: SCALE_AND_DIST_INT   (short,  2); break;        \
     390      case  32: SCALE_AND_DIST_INT_PRINT   (int,    4, TYPE); break;    \
     391      case -32: SCALE_AND_DIST_FLOAT (float,  4); break;        \
     392      case -64: SCALE_AND_DIST_FLOAT (double, 8); break;                                                \
     393      default: abort();                                 \
     394    } }
     395
     396  // this macro sets up the outer switch and calls above the macro with all RAW buffer bitpix options
     397  //
     398# define SETUP_RAWSIZE(ITYPE, ISIZE) {                  \
     399    ITYPE *RAWptr = (ITYPE *) &raw[i*ISIZE*Ztile[0]];   \
    367400    switch (matrix->bitpix) {                           \
    368401      case   8: SCALE_AND_DIST_INT   (char,   1); break;        \
     
    475508      char *srcptr = &matrix->buffer[size*(offset + start) + k];
    476509# endif
    477       char *rawptr = &raw[i*size*Ztile[0] + k*Nraw];   
     510      char *rawptr = &raw[i*Ztile[0] + k*Nraw];
    478511      for (j = 0; j < Ztile[0]; j++, srcptr += size, rawptr ++) {               
    479512        if (FALSE && (i == 0) && (j < 4) && (pass == 0)) {
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c

    r38366 r38399  
    234234  int i, Nbyte;
    235235
     236  // NONE should be swapped to mimic swapping types
     237  if (!strcasecmp(cmptype, "NONE")) {
     238    if (out_bitpix ==   8) return (1);
     239    if (out_bitpix ==  16) return (2);
     240    if (out_bitpix ==  32) return (4);
     241    if (out_bitpix == -32) return (4);
     242    if (out_bitpix == -64) return (8);
     243    return (1);
     244  }
     245
    236246  // GZIP_1, GZIP_2 should not be swapped after compression
    237247  if (!strcasecmp(cmptype, "GZIP_1") ||
    238248      !strcasecmp(cmptype, "GZIP_2") ||
    239       !strcasecmp(cmptype, "NONE_2") ||
    240       !strcasecmp(cmptype, "NONE")) {
     249      !strcasecmp(cmptype, "NONE_2")) {
    241250    if (out_bitpix ==   8) return (1);
    242251    if (out_bitpix ==  16) return (1);
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c

    r38366 r38399  
    262262    int k;
    263263    fprintf (stderr, "unc tbl: ");
    264     for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", ftable->buffer[k]); }
     264    for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", ftable->buffer[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    265265    fprintf (stderr, "\n");
    266266  }
     
    279279      int k;
    280280      fprintf (stderr, "unc dat: ");
    281       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     281      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    282282      fprintf (stderr, "\n");
    283283    }
    284284
    285     if (strcasecmp(cmptype, "NONE") &&
    286         strcasecmp(cmptype, "NONE_2") &&
     285    if (strcasecmp(cmptype, "NONE_2") && // strcasecmp(cmptype, "NONE") &&
    287286        strcasecmp(cmptype, "GZIP_1") &&
    288287        strcasecmp(cmptype, "GZIP_2") &&
     
    296295      int k;
    297296      fprintf (stderr, "unc SWP: ");
    298       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     297      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    299298      fprintf (stderr, "\n");
    300299      fprintf (stderr, "Nout  : %d -> ", Nout);
     
    310309      fprintf (stderr, "%d\n", Nout);
    311310      fprintf (stderr, "unc swp: ");
    312       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", out[k]); }
     311      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", out[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    313312      fprintf (stderr, "\n");
    314313    }
     
    322321      int k;
    323322      fprintf (stderr, "unc raw: ");
    324       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", out[k]); }
     323      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", out[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    325324      fprintf (stderr, "\n");
    326325    }
     
    336335      int k;
    337336      fprintf (stderr, "unc mat: ");
    338       for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", matrix->buffer[k]); }
     337      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", matrix->buffer[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    339338      fprintf (stderr, "\n");
    340339    }
     
    404403  int offset = 0;
    405404
    406   // we need to set up switches for all of the possible combinations:
    407   // this macro is used at the inner switch to run the actual loop
    408 # define SCALE_AND_DIST_INT(TYPE, SIZE) {                               \
     405  int directCopy = (zzero == 0.0) && (zscale == 1.0);
     406
     407# define SCALE_AND_DIST_INT_PRINT(TYPE, SIZE) {                         \
    409408    TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)];    \
    410409    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
     
    412411        *TILEptr = oblank;                                              \
    413412      } else {                                                          \
    414         *TILEptr = *RAWptr * zscale + zzero;                            \
     413        *TILEptr = directCopy ? *RAWptr : *RAWptr * zscale + zzero;     \
     414        fprintf (stderr, "dis: %08x : %08x\n", *TILEptr, *RAWptr); \
    415415      } } }
    416416
    417417  // we need to set up switches for all of the possible combinations:
    418418  // this macro is used at the inner switch to run the actual loop
    419 # define SCALE_AND_DIST_FLOAT(TYPE, SIZE) {                             \
    420     TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)];    \
     419# define SCALE_AND_DIST_INT(OTYPE, OSIZE) {                             \
     420    OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \
     421    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
     422      if (*TILEptr == zblank) {                                         \
     423        *TILEptr = oblank;                                              \
     424      } else {                                                          \
     425        if (directCopy) {                                               \
     426          *TILEptr = *RAWptr;                                           \
     427        } else {                                                        \
     428          *TILEptr = *RAWptr * zscale + zzero;                          \
     429        } } } }
     430
     431  // we need to set up switches for all of the possible combinations:
     432  // this macro is used at the inner switch to run the actual loop
     433# define SCALE_AND_DIST_FLOAT(OTYPE, OSIZE) {                           \
     434    OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \
    421435    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
    422436      if (!isfinite(*TILEptr)) {                                        \
    423437        *TILEptr = oblank;                                              \
    424438      } else {                                                          \
    425         *TILEptr = *RAWptr * zscale + zzero;                            \
    426       } } }
     439        if (directCopy) {                                               \
     440          *TILEptr = *RAWptr;                                           \
     441        } else {                                                        \
     442          *TILEptr = *RAWptr * zscale + zzero;                          \
     443        } } } }
    427444 
    428445  // this macro sets up the outer switch and calls above macro with all output bitpix options
    429 # define SETUP_RAWSIZE(TYPE, SIZE) {               \
     446# define SETUP_RAWSIZE(ITYPE, ISIZE) {             \
     447    ITYPE *RAWptr = (ITYPE *) &raw[i*ISIZE*Ztile[0]]; \
     448    switch (matrix->bitpix) {                      \
     449      case   8: SCALE_AND_DIST_INT   (char,   1); break; \
     450      case  16: SCALE_AND_DIST_INT   (short,  2); break; \
     451      case  32: SCALE_AND_DIST_INT   (int,    4); break; \
     452      case -32: SCALE_AND_DIST_FLOAT (float,  4); break; \
     453      case -64: SCALE_AND_DIST_FLOAT (double, 8); break; \
     454      default:  abort(); \
     455    } }
     456
     457  // this macro sets up the outer switch and calls above macro with all output bitpix options
     458# define SETUP_RAWSIZE_PRINT(TYPE, SIZE) {                 \
    430459    TYPE *RAWptr = (TYPE *) &raw[i*SIZE*Ztile[0]]; \
    431460    switch (matrix->bitpix) {                      \
    432461      case   8: SCALE_AND_DIST_INT   (char,   1); break; \
    433462      case  16: SCALE_AND_DIST_INT   (short,  2); break; \
    434       case  32: SCALE_AND_DIST_INT   (int,    4); break; \
     463      case  32: SCALE_AND_DIST_INT (int,    4); break; \
    435464      case -32: SCALE_AND_DIST_FLOAT (float,  4); break; \
    436465      case -64: SCALE_AND_DIST_FLOAT (double, 8); break; \
     
    534563      char *srcptr = &matrix->buffer[size*(offset + start) + k];
    535564# endif
    536       char *rawptr = &raw[i*size*Ztile[0] + k*Nraw];   
     565      char *rawptr = &raw[i*Ztile[0] + k*Nraw];
    537566      for (j = 0; j < Ztile[0]; j++, srcptr += size, rawptr ++) {               
    538567        if (FALSE && (i == 0) && (j < 4) && (pass == 0)) {
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c

    r38366 r38399  
    7878    if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE;
    7979
    80     // for now we set all fields to the requested type
     80    // for now we set all fields to the requested type.  since I do not yet know the column data types I cannot yet assign automatic cmptypes
    8181    strcpy (fields[i].zctype, zcmptype);
    8282
     
    127127    fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize;
    128128    max_width = MAX(max_width, fields[i].rowsize);
     129
     130    if (!strcasecmp (fields[i].zctype, "AUTO")) {
     131      if (!strcmp (fields[i].datatype, "float") ||
     132          !strcmp (fields[i].datatype, "double")||
     133          !strcmp (fields[i].datatype, "int64_t")) {
     134        strcpy (fields[i].zctype, "GZIP_2");
     135        goto got_cmptype;
     136      }
     137      if (!strcmp (fields[i].datatype, "byte") ||
     138          !strcmp (fields[i].datatype, "short") ||
     139          !strcmp (fields[i].datatype, "int")) {
     140        strcpy (fields[i].zctype, "RICE_1");
     141        goto got_cmptype;
     142      }
     143      if (!strcmp (fields[i].datatype, "char")) {
     144        strcpy (fields[i].zctype, "GZIP_1");
     145        goto got_cmptype;
     146      }
     147    }
     148  got_cmptype:
     149
    129150
    130151    // RICE can only be used on integer fields
  • branches/eam_branches/ohana.20150429/src/libfits/test/imagecomp.c

    r38366 r38399  
    44
    55int test_compress (int bitpix, char *zcmptype);
     6int test_compress_fullrange (int bitpix, char *zcmptype);
     7int test_compress_fulltile (int bitpix, char *zcmptype);
    68
    79// char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "PLIO_1", "RICE_1", "RICE_ONE", "HCOMPRESS_1", NULL};
     
    911int bitpix[] = {8, 16, 32, -32, -64, 0};
    1012
     13// char *cmptype[] = {"NONE_2", NULL};
     14// int bitpix[] = {16, 0};
     15
     16static int NX = 10;
     17static int NY = 10;
     18
    1119int main (int argc, char **argv) {
    1220 
    13   plan_tests (64);
     21  plan_tests (3*3*234);
    1422
    1523  diag ("libfits imagecomp.c tests");
     
    2129      if (!strcasecmp (cmptype[i], "RICE_ONE") && (bitpix[j] < 0)) continue;
    2230      test_compress (bitpix[j], cmptype[i]);
     31      test_compress_fulltile (bitpix[j], cmptype[i]);
     32      test_compress_fullrange (bitpix[j], cmptype[i]);
    2333    }
    2434  }
    25   exit (0);
     35
     36  NX = 100; NY = 33;
     37  for (i = 0; cmptype[i]; i++) {
     38    for (j = 0; bitpix[j]; j++) {
     39      if (!strcasecmp (cmptype[i], "RICE_1") && (bitpix[j] < 0)) continue;
     40      if (!strcasecmp (cmptype[i], "RICE_ONE") && (bitpix[j] < 0)) continue;
     41      test_compress (bitpix[j], cmptype[i]);
     42      test_compress_fulltile (bitpix[j], cmptype[i]);
     43      test_compress_fullrange (bitpix[j], cmptype[i]);
     44    }
     45  }
     46
     47  NX = 357; NY = 245;
     48  for (i = 0; cmptype[i]; i++) {
     49    for (j = 0; bitpix[j]; j++) {
     50      if (!strcasecmp (cmptype[i], "RICE_1") && (bitpix[j] < 0)) continue;
     51      if (!strcasecmp (cmptype[i], "RICE_ONE") && (bitpix[j] < 0)) continue;
     52      test_compress (bitpix[j], cmptype[i]);
     53      test_compress_fulltile (bitpix[j], cmptype[i]);
     54      test_compress_fullrange (bitpix[j], cmptype[i]);
     55    }
     56  }
     57  return exit_status();
    2658}
    27 
    28 # define NX 10
    29 # define NY 10
    3059
    3160int test_compress (int bitpix, char *zcmptype) { // make a table, compress, uncompress, compare : use compression zcmptype
     
    77106  }     
    78107
     108  // int Ztile[2] = {NX, NY};
     109  // ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, (int *) &Ztile, zcmptype), "compressed image");
    79110  ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, NULL, zcmptype), "compressed image");
    80 
    81111  ok (gfits_uncompress_image (&outheader, &outmatrix, &ftable), "uncompressed image");
    82112 
     
    115145}
    116146
     147int test_compress_fulltile (int bitpix, char *zcmptype) { // make a table, compress, uncompress, compare : use compression zcmptype
     148
     149  Header rawheader;
     150  Matrix rawmatrix;
     151  Header outheader;
     152  Matrix outmatrix;
     153
     154  Header theader;
     155  FTable ftable;
     156  ftable.header = &theader;
     157
     158  diag ("--- starting test_compress with bitpix %d, zcmptype %s ---", bitpix, zcmptype);
     159  ok (gfits_init_header (&rawheader), "init'ed the raw header");
     160  ok (gfits_init_matrix (&rawmatrix), "init'ed the raw matrix");
     161  ok (gfits_init_header (&outheader), "init'ed the out header");
     162  ok (gfits_init_matrix (&outmatrix), "init'ed the out matrix");
     163
     164  /* assign the necessary internal values */
     165  rawheader.bitpix   = bitpix;
     166  rawheader.Naxes = 2;
     167  rawheader.Naxis[0] = NX;
     168  rawheader.Naxis[1] = NY;
     169
     170  /* create the appropriate header and matrix */
     171  ok (gfits_create_header (&rawheader),          "created header");
     172  ok (gfits_create_matrix (&rawheader, &rawmatrix), "created matrix");
     173 
     174  char   *rawdata_char   = (char   *) rawmatrix.buffer;
     175  short  *rawdata_short  = (short  *) rawmatrix.buffer;
     176  int    *rawdata_int    = (int    *) rawmatrix.buffer;
     177  float  *rawdata_float  = (float  *) rawmatrix.buffer;
     178  double *rawdata_double = (double *) rawmatrix.buffer;
     179 
     180  int ix, iy;
     181  for (ix = 0; ix < NX; ix++) {
     182    for (iy = 0; iy < NY; iy++) {
     183      int IY = iy + 1;
     184      switch (bitpix) {
     185        case   8: rawdata_char  [ix + NX*iy] = ix + IY*IY; break;
     186        case  16: rawdata_short [ix + NX*iy] = ix + IY*IY; break;
     187        case  32: rawdata_int   [ix + NX*iy] = ix + IY*IY; break;
     188        case -32: rawdata_float [ix + NX*iy] = ix + IY*IY; break;
     189        case -64: rawdata_double[ix + NX*iy] = ix + IY*IY; break;
     190        default: myAbort ("bad bitpix value");
     191      }
     192    }
     193  }     
     194
     195  int Ztile[2] = {NX, NY};
     196  ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, (int *) &Ztile, zcmptype), "compressed image");
     197  // ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, NULL, zcmptype), "compressed image");
     198  ok (gfits_uncompress_image (&outheader, &outmatrix, &ftable), "uncompressed image");
     199 
     200  gfits_free_header (&theader);
     201  gfits_free_table (&ftable);
     202 
     203  int Nbad = 0;
     204
     205  char   *outdata_char   = (char   *) outmatrix.buffer;
     206  short  *outdata_short  = (short  *) outmatrix.buffer;
     207  int    *outdata_int    = (int    *) outmatrix.buffer;
     208  float  *outdata_float  = (float  *) outmatrix.buffer;
     209  double *outdata_double = (double *) outmatrix.buffer;
     210
     211  for (ix = 0; ix < NX; ix++) {
     212    for (iy = 0; iy < NY; iy++) {
     213      switch (bitpix) {
     214        case   8: if (rawdata_char  [ix + NX*iy] != outdata_char  [ix + NX*iy]) Nbad ++; break;
     215        case  16: if (rawdata_short [ix + NX*iy] != outdata_short [ix + NX*iy]) Nbad ++; break;
     216        case  32: if (rawdata_int   [ix + NX*iy] != outdata_int   [ix + NX*iy]) Nbad ++; break;
     217        case -32: if (rawdata_float [ix + NX*iy] != outdata_float [ix + NX*iy]) Nbad ++; break;
     218        case -64: if (rawdata_double[ix + NX*iy] != outdata_double[ix + NX*iy]) Nbad ++; break;
     219        default: myAbort ("bad bitpix value");
     220      }
     221    }
     222  }     
     223 
     224  ok (!Nbad, "all image pixels match");
     225
     226  gfits_free_header (&rawheader);
     227  gfits_free_matrix (&rawmatrix);
     228
     229  gfits_free_header (&outheader);
     230  gfits_free_matrix (&outmatrix);
     231  return TRUE;
     232}
     233
     234int test_compress_fullrange (int bitpix, char *zcmptype) { // make a table, compress, uncompress, compare : use compression zcmptype
     235
     236  Header rawheader;
     237  Matrix rawmatrix;
     238  Header outheader;
     239  Matrix outmatrix;
     240
     241  Header theader;
     242  FTable ftable;
     243  ftable.header = &theader;
     244
     245  diag ("--- starting test_compress with bitpix %d, zcmptype %s ---", bitpix, zcmptype);
     246  ok (gfits_init_header (&rawheader), "init'ed the raw header");
     247  ok (gfits_init_matrix (&rawmatrix), "init'ed the raw matrix");
     248  ok (gfits_init_header (&outheader), "init'ed the out header");
     249  ok (gfits_init_matrix (&outmatrix), "init'ed the out matrix");
     250
     251  /* assign the necessary internal values */
     252  rawheader.bitpix   = bitpix;
     253  rawheader.Naxes = 2;
     254  rawheader.Naxis[0] = NX;
     255  rawheader.Naxis[1] = NY;
     256
     257  /* create the appropriate header and matrix */
     258  ok (gfits_create_header (&rawheader),          "created header");
     259  ok (gfits_create_matrix (&rawheader, &rawmatrix), "created matrix");
     260 
     261  char   *rawdata_char   = (char   *) rawmatrix.buffer;
     262  short  *rawdata_short  = (short  *) rawmatrix.buffer;
     263  int    *rawdata_int    = (int    *) rawmatrix.buffer;
     264  float  *rawdata_float  = (float  *) rawmatrix.buffer;
     265  double *rawdata_double = (double *) rawmatrix.buffer;
     266 
     267  long A = time(NULL);
     268  srand48(A);
     269  // srand48(1);
     270
     271  int ix, iy;
     272  for (ix = 0; ix < NX; ix++) {
     273    for (iy = 0; iy < NY; iy++) {
     274      switch (bitpix) {
     275        case   8: rawdata_char  [ix + NX*iy] =       0xff & lrand48(); break;
     276        case  16: rawdata_short [ix + NX*iy] =     0xffff & lrand48(); break;
     277        case  32: rawdata_int   [ix + NX*iy] = 0xffffffff & lrand48(); break;
     278        case -32: rawdata_float [ix + NX*iy] = FLT_MAX * (2.0*drand48() - 1.0); break;
     279        case -64: rawdata_double[ix + NX*iy] = DBL_MAX * (2.0*drand48() - 1.0); break;
     280        default: myAbort ("bad bitpix value");
     281      }
     282    }
     283  }     
     284
     285  // int Ztile[2] = {NX, NY};
     286  ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, NULL, zcmptype), "compressed image");
     287
     288  ok (gfits_uncompress_image (&outheader, &outmatrix, &ftable), "uncompressed image");
     289 
     290  gfits_free_header (&theader);
     291  gfits_free_table (&ftable);
     292 
     293  int Nbad = 0;
     294
     295  char   *outdata_char   = (char   *) outmatrix.buffer;
     296  short  *outdata_short  = (short  *) outmatrix.buffer;
     297  int    *outdata_int    = (int    *) outmatrix.buffer;
     298  float  *outdata_float  = (float  *) outmatrix.buffer;
     299  double *outdata_double = (double *) outmatrix.buffer;
     300
     301  for (ix = 0; ix < NX; ix++) {
     302    for (iy = 0; iy < NY; iy++) {
     303      switch (bitpix) {
     304        case   8: if (rawdata_char  [ix + NX*iy] != outdata_char  [ix + NX*iy]) Nbad ++; break;
     305        case  16: if (rawdata_short [ix + NX*iy] != outdata_short [ix + NX*iy]) Nbad ++; break;
     306        case  32: if (rawdata_int   [ix + NX*iy] != outdata_int   [ix + NX*iy]) Nbad ++; break;
     307        case -32: if (rawdata_float [ix + NX*iy] != outdata_float [ix + NX*iy]) Nbad ++; break;
     308        case -64: if (rawdata_double[ix + NX*iy] != outdata_double[ix + NX*iy]) Nbad ++; break;
     309        default: myAbort ("bad bitpix value");
     310      }
     311    }
     312  }     
     313 
     314  ok (!Nbad, "all image pixels match");
     315
     316  gfits_free_header (&rawheader);
     317  gfits_free_matrix (&rawmatrix);
     318
     319  gfits_free_header (&outheader);
     320  gfits_free_matrix (&outmatrix);
     321  return TRUE;
     322}
     323
     324
     325// fprintf (stderr, "%2d %2d : 0x%08x vs 0x%08x vs 0x%08x : %d\n", ix, iy, rawdata_int   [ix + NX*iy], outdata_int   [ix + NX*iy], tmpbuff[ix + NX*iy], outdata_int   [ix + NX*iy] - rawdata_int   [ix + NX*iy]);
  • branches/eam_branches/ohana.20150429/src/libfits/test/ricetest.c

    r38356 r38399  
    88int main (int argc, char **argv) {
    99 
    10   plan_tests (64);
     10  plan_tests (45);
     11
     12  diag ("libfits ricetest.c tests");
    1113
    1214  // buffers to store max array
     
    1416  char cmpdata[NBYTE];
    1517  char outdata[NBYTE];
     18
     19  if (1) {
     20    char *rawvalue = (char *) rawdata;
     21    char *outvalue = (char *) outdata;
     22
     23    int j;
     24    for (j = 0; j < 5; j++) {
     25      int i;
     26      for (i = 0; i < NPIX; i++) {
     27        rawvalue[i] = i;
     28      }
     29
     30      int Ncmp = fits_rcomp_byte (rawvalue, NPIX, cmpdata, NBYTE, 32);
     31      ok (Ncmp > 0, "compressed byte data");
     32
     33      int status = fits_rdecomp_byte (cmpdata, Ncmp, outdata, NPIX, 32);
     34      ok (!status, "decompressed byte data");
     35
     36      int Nbad = 0;
     37      for (i = 0; i < NPIX; i++) {
     38        if (rawvalue[i] != outvalue[i]) Nbad ++;
     39      }
     40
     41      ok (!Nbad, "values match");
     42    }
     43  }
    1644
    1745  if (1) {
     
    2755
    2856      int Ncmp = fits_rcomp_short (rawvalue, NPIX, cmpdata, NBYTE, 32);
    29       fprintf (stderr, "Ncmp: %d\n", Ncmp);
     57      ok (Ncmp > 0, "compressed short data");
    3058
    3159      int status = fits_rdecomp_short (cmpdata, Ncmp, outdata, NPIX, 32);
    32       fprintf (stderr, "status: %d\n", status);
     60      ok (!status, "decompressed short data");
    3361
    3462      int Nbad = 0;
     
    4169  }
    4270
    43   if (0) {
     71  if (1) {
    4472    int *rawvalue = (int *) rawdata;
    4573    int *outvalue = (int *) outdata;
     
    5381
    5482      int Ncmp = fits_rcomp (rawvalue, NPIX, cmpdata, NBYTE, 32);
    55       fprintf (stderr, "Ncmp: %d\n", Ncmp);
     83      ok (Ncmp > 0, "compressed int data");
    5684
    5785      int status = fits_rdecomp (cmpdata, Ncmp, outdata, NPIX, 32);
    58       fprintf (stderr, "status: %d\n", status);
     86      ok (!status, "decompressed int data");
    5987
    6088      int Nbad = 0;
     
    6290        if (rawvalue[i] != outvalue[i]) Nbad ++;
    6391      }
    64 
    6592      ok (!Nbad, "values match");
    6693    }
    6794  }
    68   exit (0);
     95  return exit_status();
    6996}
  • branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c

    r38366 r38399  
    44
    55int test_compress (char *zcmptype);
     6int test_compress_fullrange (char *zcmptype);
    67int test_compress_single_full (char *zcmptype);
    78
     9char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "RICE_1", "RICE_ONE", "AUTO", NULL};
     10
    811int main (int argc, char **argv) {
    912 
    10   plan_tests (64);
     13  plan_tests (286);
    1114
    1215  diag ("libfits tablecomp.c tests");
    1316
    14   test_compress_single_full ("GZIP_1");
    15   test_compress_single_full ("RICE_1");
    16 
    1717  test_compress (NULL);
    18   test_compress ("NONE");
    19   test_compress ("NONE_2");
    20   test_compress ("GZIP_1");
    21   test_compress ("GZIP_2");
    22   test_compress ("RICE_1");
    23   test_compress ("RICE_ONE");
    24 
    25   exit (0);
     18  test_compress_fullrange (NULL);
     19
     20  int i;
     21  for (i = 0; cmptype[i]; i++) {
     22    test_compress (cmptype[i]);
     23    test_compress_fullrange (cmptype[i]);
     24  }
     25
     26  // test_compress_single_full ("GZIP_1");
     27  // test_compress_single_full ("RICE_1");
     28
     29  // test_compress (NULL);
     30  // test_compress ("NONE");
     31  // test_compress ("NONE_2");
     32  // test_compress ("GZIP_1");
     33  // test_compress ("GZIP_2");
     34  // test_compress ("RICE_1");
     35  // test_compress ("RICE_ONE");
     36  // test_compress ("AUTO");
     37
     38  // test_compress_fullrange (NULL);
     39  // test_compress_fullrange ("NONE");
     40
     41  return exit_status();
    2642}
    2743
     
    3753  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
    3854
    39   ok (gfits_define_bintable_column (&header, "B", "VAL", "val", "none", 1.0, 0.0), "defined byte column");
    40   ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
    41   ok (gfits_define_bintable_column (&header, "J", "ID",  "ID", "none", 1.0, 0.0),  "defined int column");
    42   ok (gfits_define_bintable_column (&header, "E", "X", "x", "degree", 1.0, 0.0),   "defined float column");
    43   ok (gfits_define_bintable_column (&header, "D", "Y", "y", "degree", 1.0, 0.0),   "defined double column");
     55  ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte",   "none", 1.0, 0.0), "defined byte column");
     56  ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short",  "none", 1.0, 0.0), "defined short column");
     57  ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int",    "none", 1.0, 0.0),  "defined int column");
     58  ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long",   "none", 1.0, 0.0),  "defined long column");
     59  ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float",  "degree", 1.0, 0.0),   "defined float column");
     60  ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0),   "defined double column");
    4461 
    4562  // generate the output array that carries the data
     
    4764
    4865  int Nval = 1000;
    49   char  *VAL;  ALLOCATE (VAL, char,   Nval);
    50   short *SEQ;  ALLOCATE (SEQ, short,  Nval);
    51   int    *ID;  ALLOCATE (ID,  int,    Nval);
    52   float   *X;  ALLOCATE (X,   float,  Nval);
    53   double  *Y;  ALLOCATE (Y,   double, Nval);
     66  char    *VAL_B;  ALLOCATE (VAL_B, char,    Nval);
     67  short   *VAL_I;  ALLOCATE (VAL_I, short,   Nval);
     68  int     *VAL_J;  ALLOCATE (VAL_J, int,     Nval);
     69  int64_t *VAL_K;  ALLOCATE (VAL_K, int64_t, Nval);
     70  float   *VAL_E;  ALLOCATE (VAL_E, float,   Nval);
     71  double  *VAL_D;  ALLOCATE (VAL_D, double,  Nval);
    5472 
    5573  int i;
    5674  for (i = 0; i < Nval; i++) {
    57     VAL[i] = i + 32;
    58     SEQ[i] = i;
    59     ID[i] = 10000*i + 100*i;
    60     X[i] = 0.1*i;
    61     Y[i] = 1.001*i;
     75    VAL_B[i] = (i % 255) - 128;
     76    VAL_I[i] = i;
     77    VAL_J[i] = 10000*i + 100*i;
     78    VAL_K[i] = 10000*i + 330*i;
     79    VAL_E[i] = 0.1*i;
     80    VAL_D[i] = 1.001*i;
    6281  }     
    6382
    6483  // add the columns to the output array
    65   ok (gfits_set_bintable_column (&header, &ftable, "VAL", VAL, Nval), "set byte   table column");
    66   ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
    67   ok (gfits_set_bintable_column (&header, &ftable,  "ID",  ID, Nval), "set int    table column");
    68   ok (gfits_set_bintable_column (&header, &ftable,   "X",   X, Nval), "set float  table column");
    69   ok (gfits_set_bintable_column (&header, &ftable,   "Y",   Y, Nval), "set double table column");
     84  ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte   table column");
     85  ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short  table column");
     86  ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int    table column");
     87  ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long   table column");
     88  ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float  table column");
     89  ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column");
    7090
    7191  Header *outheader = &header;
     
    94114  off_t Nrow;
    95115
    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");
    97   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");
    98   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");
    99   float    *X_t = gfits_get_bintable_column_data (outheader, outtable,   "X", type, &Nrow, &Ncol); ok (!strcmp (type, "float"),  "read float  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    100   double   *Y_t = gfits_get_bintable_column_data (outheader, outtable,   "Y", type, &Nrow, &Ncol); ok (!strcmp (type, "double"), "read double table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     116  char    *VAL_B_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_B", 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");
     117  short   *VAL_I_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_I", 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");
     118  int     *VAL_J_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_J", 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");
     119  int64_t *VAL_K_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_K", type, &Nrow, &Ncol); ok (!strcmp (type, "int64_t"), "read int64_t table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     120  float   *VAL_E_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_E", type, &Nrow, &Ncol); ok (!strcmp (type, "float"),   "read float   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     121  double  *VAL_D_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_D", type, &Nrow, &Ncol); ok (!strcmp (type, "double"),  "read double  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    101122
    102123  // count mismatched values
    103   int Nvalue = 0;
    104   int Nseq = 0;
    105   int  Nid = 0;
    106   int   Nx = 0;
    107   int   Ny = 0;
    108   for (i = 0; i < Nval; i++) {
    109     if (VAL[i] != VAL_t[i]) Nvalue++;
    110     if (SEQ[i] != SEQ_t[i]) Nseq++;
    111     if ( ID[i] !=  ID_t[i]) Nid++;
    112     if (  X[i] !=   X_t[i]) Nx++;
    113     if (  Y[i] !=   Y_t[i]) Ny++;
    114   }
    115 
    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)");
     124  int NVAL_B_bad = 0;
     125  int NVAL_I_bad = 0;
     126  int NVAL_J_bad = 0;
     127  int NVAL_K_bad = 0;
     128  int NVAL_E_bad = 0;
     129  int NVAL_D_bad = 0;
     130
     131  // for (i = 0; i < Nval; i++) {
     132  //   fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);
     133  // }
     134
     135  for (i = 0; i < Nval; i++) {
     136    if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
     137    if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++;
     138    if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++;
     139    if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++;
     140    if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++;
     141    if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++;
     142  }
     143
     144  ok (!NVAL_B_bad, "byte    values match (input vs output)");
     145  ok (!NVAL_I_bad, "short   values match (input vs output)");
     146  ok (!NVAL_J_bad, "int     values match (input vs output)");
     147  ok (!NVAL_K_bad, "int64_t values match (input vs output)");
     148  ok (!NVAL_E_bad, "float   values match (input vs output)");
     149  ok (!NVAL_D_bad, "double  values match (input vs output)");
    121150
    122151  gfits_free_header (&header);
     
    129158}
    130159
    131 int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
     160int test_compress_fullrange (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
    132161
    133162  Header header;
     
    140169  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
    141170
    142   ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
     171  ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte",   "none", 1.0, 0.0), "defined byte column");
     172  ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short",  "none", 1.0, 0.0), "defined short column");
     173  ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int",    "none", 1.0, 0.0),  "defined int column");
     174  ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long",   "none", 1.0, 0.0),  "defined long column");
     175  ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float",  "degree", 1.0, 0.0),   "defined float column");
     176  ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0),   "defined double column");
    143177 
    144178  // generate the output array that carries the data
     
    146180
    147181  int Nval = 1000;
    148   short *SEQ;  ALLOCATE (SEQ, short,  Nval);
    149  
     182  char    *VAL_B;  ALLOCATE (VAL_B, char,    Nval);
     183  short   *VAL_I;  ALLOCATE (VAL_I, short,   Nval);
     184  int     *VAL_J;  ALLOCATE (VAL_J, int,     Nval);
     185  int64_t *VAL_K;  ALLOCATE (VAL_K, int64_t, Nval);
     186  float   *VAL_E;  ALLOCATE (VAL_E, float,   Nval);
     187  double  *VAL_D;  ALLOCATE (VAL_D, double,  Nval);
     188 
     189  long A = time(NULL);
     190  srand48(A);
     191
    150192  int i;
    151193  for (i = 0; i < Nval; i++) {
    152     SEQ[i] = i;
     194    VAL_B[i] =       0xff & lrand48();
     195    VAL_I[i] =     0xffff & lrand48();
     196    VAL_J[i] = 0xffffffff & lrand48();
     197    VAL_K[i] = (((int64_t)lrand48()) << 32) + (int64_t)lrand48();
     198    VAL_E[i] = FLT_MAX * (2.0*drand48() - 1.0);
     199    VAL_D[i] = DBL_MAX * (2.0*drand48() - 1.0);
    153200  }     
    154201
    155202  // add the columns to the output array
    156   ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
     203  ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte   table column");
     204  ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short  table column");
     205  ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int    table column");
     206  ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long   table column");
     207  ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float  table column");
     208  ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column");
    157209
    158210  Header *outheader = &header;
     
    163215    FTable cmptable;
    164216    cmptable.header = &cmpheader;
    165     ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
     217    ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table");
    166218
    167219    Header rawheader;
     
    181233  off_t Nrow;
    182234
     235  char    *VAL_B_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_B", 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");
     236  short   *VAL_I_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_I", 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");
     237  int     *VAL_J_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_J", 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");
     238  int64_t *VAL_K_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_K", type, &Nrow, &Ncol); ok (!strcmp (type, "int64_t"), "read int64_t table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     239  float   *VAL_E_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_E", type, &Nrow, &Ncol); ok (!strcmp (type, "float"),   "read float   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     240  double  *VAL_D_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_D", type, &Nrow, &Ncol); ok (!strcmp (type, "double"),  "read double  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     241
     242  // count mismatched values
     243  int NVAL_B_bad = 0;
     244  int NVAL_I_bad = 0;
     245  int NVAL_J_bad = 0;
     246  int NVAL_K_bad = 0;
     247  int NVAL_E_bad = 0;
     248  int NVAL_D_bad = 0;
     249
     250  for (i = 0; i < Nval; i++) {
     251    if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
     252    if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++;
     253    if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++;
     254    if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++;
     255    if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++;
     256    if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++;
     257  }
     258
     259  ok (!NVAL_B_bad, "byte    values match (input vs output)");
     260  ok (!NVAL_I_bad, "short   values match (input vs output)");
     261  ok (!NVAL_J_bad, "int     values match (input vs output)");
     262  ok (!NVAL_K_bad, "int64_t values match (input vs output)");
     263  ok (!NVAL_E_bad, "float   values match (input vs output)");
     264  ok (!NVAL_D_bad, "double  values match (input vs output)");
     265
     266  gfits_free_header (&header);
     267  gfits_free_table (&ftable);
     268  if (zcmptype) {
     269    gfits_free_header (outheader);
     270    gfits_free_table (outtable);
     271  }
     272  return TRUE;
     273}
     274
     275int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
     276
     277  Header header;
     278  FTable ftable;
     279
     280  diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
     281  ok (gfits_init_header (&header), "inited the header");
     282  ok (gfits_init_table (&ftable), "inited the table");
     283
     284  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
     285
     286  ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
     287 
     288  // generate the output array that carries the data
     289  ok (gfits_create_table (&header, &ftable), "created the basic table");
     290
     291  int Nval = 1000;
     292  short *SEQ;  ALLOCATE (SEQ, short,  Nval);
     293 
     294  int i;
     295  for (i = 0; i < Nval; i++) {
     296    SEQ[i] = i;
     297  }     
     298
     299  // add the columns to the output array
     300  ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
     301
     302  Header *outheader = &header;
     303  FTable *outtable = &ftable;
     304
     305  if (zcmptype) {
     306    Header cmpheader;
     307    FTable cmptable;
     308    cmptable.header = &cmpheader;
     309    ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
     310
     311    Header rawheader;
     312    FTable rawtable;
     313    rawtable.header = &rawheader;
     314    ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
     315   
     316    gfits_free_header (&cmpheader);
     317    gfits_free_table (&cmptable);
     318
     319    outheader = &rawheader;
     320    outtable  = &rawtable;
     321  }
     322
     323  char type[16];
     324  int Ncol;
     325  off_t Nrow;
     326
    183327  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");
    184328
  • branches/eam_branches/ohana.20150429/src/libfits/test/zlib.c

    r38334 r38399  
    4141    }
    4242
     43# ifdef VERBOSE
    4344    char *rawdata = (char *) srcbuf;
    4445    fprintf (stderr, "inp: ");
     
    4748    }
    4849    fprintf (stderr, "\n");
     50# endif
    4951
    5052    // the '5' is the compression level: make this a user argument
    5153    err = deflateInit(&zdn, 5);
    52     fprintf (stderr, "inp buffers cmp 0: %d => %d => %d\n", zdn.avail_in, zdn.avail_out, (int) zdn.total_out);
     54    // fprintf (stderr, "inp buffers cmp 0: %d => %d => %d\n", zdn.avail_in, zdn.avail_out, (int) zdn.total_out);
    5355    if (err != Z_OK) { fprintf (stderr, "error 1: %d vs %d\n", err, Z_OK); exit (1); }
    5456 
    5557    err = deflate(&zdn, Z_FINISH);
    56     fprintf (stderr, "out buffers cmp 1: %d => %d => %d\n", zdn.avail_in, zdn.avail_out, (int) zdn.total_out);
     58    // fprintf (stderr, "out buffers cmp 1: %d => %d => %d\n", zdn.avail_in, zdn.avail_out, (int) zdn.total_out);
    5759    if (err != Z_STREAM_END) { fprintf (stderr, "error 2: %d vs %d\n", err, Z_STREAM_END); exit (2); }
    58     fprintf (stderr, "out buffers cmp 2: %d => %d => %d\n", zdn.avail_in, zdn.avail_out, (int) zdn.total_out);
     60    // fprintf (stderr, "out buffers cmp 2: %d => %d => %d\n", zdn.avail_in, zdn.avail_out, (int) zdn.total_out);
    5961
    6062    // dump out the data which failed to uncompress (and the input data)
     63# ifdef VERBOSE
    6164    char *cmpdata = (char *) tgtbuf;
    6265    fprintf (stderr, "out: ");
     
    6568    }
    6669    fprintf (stderr, "\n");
     70# endif
    6771
    6872    assert (zdn.total_out <= NTGT*sizeof(double));
    6973
    70     fprintf (stderr, "result: %d bytes\n", (int) zdn.total_out);
     74    // fprintf (stderr, "result: %d bytes\n", (int) zdn.total_out);
    7175    // for (i = 0; i < zdn.total_out / sizeof(double); i++) {
    7276    //   fprintf (stderr, "%d : 0x%02hhx\n", i, tgtbuf[i]);
     
    8791    // the '5' is the compression level: make this a user argument
    8892    err = inflateInit(&zup);
    89     fprintf (stderr, "out buffers unc 0: %d => %d => %d\n", zup.avail_in, zup.avail_out, (int) zup.total_out);
     93    // fprintf (stderr, "out buffers unc 0: %d => %d => %d\n", zup.avail_in, zup.avail_out, (int) zup.total_out);
    9094    if (err != Z_OK) { fprintf (stderr, "error 1: %d vs %d\n", err, Z_OK); exit (1); }
    9195 
    9296    err = inflate(&zup, Z_FINISH);
    93     fprintf (stderr, "out buffers unc 1: %d => %d => %d\n", zup.avail_in, zup.avail_out, (int) zup.total_out);
     97    // fprintf (stderr, "out buffers unc 1: %d => %d => %d\n", zup.avail_in, zup.avail_out, (int) zup.total_out);
    9498    if (err != Z_STREAM_END) { fprintf (stderr, "error 2: %d vs %d\n", err, Z_STREAM_END); exit (2); }
    95     fprintf (stderr, "out buffers unc 2: %d => %d => %d\n", zup.avail_in, zup.avail_out, (int) zup.total_out);
     99    // fprintf (stderr, "out buffers unc 2: %d => %d => %d\n", zup.avail_in, zup.avail_out, (int) zup.total_out);
    96100
     101# ifdef VERBOSE
    97102    char *outdata = (char *) outbuf;
    98103    fprintf (stderr, "unc: ");
     
    101106    }
    102107    fprintf (stderr, "\n");
     108# endif
    103109
    104110    assert (zup.total_out <= NTGT*sizeof(double));
    105111
    106     fprintf (stderr, "result: %d bytes\n", (int) zup.total_out);
     112    // fprintf (stderr, "result: %d bytes\n", (int) zup.total_out);
    107113    for (i = 0; 0 && i < zup.total_out / sizeof(double); i++) {
    108       fprintf (stderr, "%d : %f : %f\n", i, outbuf[i], srcbuf[i]);
     114      // fprintf (stderr, "%d : %f : %f\n", i, outbuf[i], srcbuf[i]);
    109115      assert (outbuf[i] == srcbuf[i]);
    110116    }
    111117  }
    112 
    113   exit (0);
     118  return exit_status();
    114119}
    115120
     
    175180    }
    176181  }
    177 
    178   exit (0);
     182  return exit_status();
    179183}
Note: See TracChangeset for help on using the changeset viewer.