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/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]);
Note: See TracChangeset for help on using the changeset viewer.