IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

File:
1 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)) {
Note: See TracChangeset for help on using the changeset viewer.