Changeset 38399
- Timestamp:
- Jun 5, 2015, 7:58:50 PM (11 years ago)
- Location:
- branches/eam_branches/ohana.20150429/src/libfits
- Files:
-
- 8 edited
-
matrix/F_compress_M.c (modified) (9 diffs)
-
matrix/F_compress_utils.c (modified) (1 diff)
-
matrix/F_uncompress_M.c (modified) (9 diffs)
-
table/F_compress_T.c (modified) (2 diffs)
-
test/imagecomp.c (modified) (5 diffs)
-
test/ricetest.c (modified) (6 diffs)
-
test/tablecomp.c (modified) (9 diffs)
-
test/zlib.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c
r38366 r38399 204 204 int k; 205 205 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, " "); } 207 207 fprintf (stderr, "\n"); 208 208 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, " "); } 210 210 fprintf (stderr, "\n"); 211 211 } … … 221 221 int k; 222 222 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, " "); } 224 224 fprintf (stderr, "\n"); 225 225 fprintf (stderr, "Nzdata: %d -> ", Nzdata); … … 233 233 fprintf (stderr, "%d\n", Nzdata); 234 234 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, " "); } 236 236 fprintf (stderr, "\n"); 237 237 } … … 240 240 // compression modes require swapping after compression (compresssion & decompression 241 241 // operate on native ENDIAN) 242 if (strcasecmp(zcmptype, "NONE") && 243 strcasecmp(zcmptype, "NONE_2") && 242 if (strcasecmp(zcmptype, "NONE_2") && // strcasecmp(zcmptype, "NONE") && 244 243 strcasecmp(zcmptype, "GZIP_1") && 245 244 strcasecmp(zcmptype, "GZIP_2") && … … 253 252 int k; 254 253 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, " "); } 256 255 fprintf (stderr, "\n"); 257 256 } … … 266 265 int k; 267 266 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, " "); } 269 268 fprintf (stderr, "\n"); 270 269 } … … 339 338 offset = 0; 340 339 340 int directCopy = (zzero == 0.0) && (zscale == 1.0); 341 341 342 // we need to set up switches for all of the possible combinations: 342 343 // 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) { \ 344 345 TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)]; \ 345 346 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 347 348 *RAWptr = zblank; \ 348 349 } 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); \ 350 353 } } } 351 354 352 355 // we need to set up switches for all of the possible combinations: 353 356 // 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)]; \ 356 373 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ 357 374 if (!isfinite(*TILEptr)) { \ 358 375 *RAWptr = zblank; \ 359 376 } else { \ 360 *RAWptr = (*TILEptr - zzero) / zscale; \ 361 } } } 377 if (directCopy) { \ 378 *RAWptr = *TILEptr; \ 379 } else { \ 380 *RAWptr = (*TILEptr - zzero) / zscale; \ 381 } } } } 362 382 363 383 // this macro sets up the outer switch and calls above the macro with all RAW buffer bitpix options 364 384 // 365 # define SETUP_RAWSIZE (TYPE, SIZE) { \385 # define SETUP_RAWSIZE_PRINT(TYPE, SIZE) { \ 366 386 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]]; \ 367 400 switch (matrix->bitpix) { \ 368 401 case 8: SCALE_AND_DIST_INT (char, 1); break; \ … … 475 508 char *srcptr = &matrix->buffer[size*(offset + start) + k]; 476 509 # endif 477 char *rawptr = &raw[i* size*Ztile[0] + k*Nraw];510 char *rawptr = &raw[i*Ztile[0] + k*Nraw]; 478 511 for (j = 0; j < Ztile[0]; j++, srcptr += size, rawptr ++) { 479 512 if (FALSE && (i == 0) && (j < 4) && (pass == 0)) { -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c
r38366 r38399 234 234 int i, Nbyte; 235 235 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 236 246 // GZIP_1, GZIP_2 should not be swapped after compression 237 247 if (!strcasecmp(cmptype, "GZIP_1") || 238 248 !strcasecmp(cmptype, "GZIP_2") || 239 !strcasecmp(cmptype, "NONE_2") || 240 !strcasecmp(cmptype, "NONE")) { 249 !strcasecmp(cmptype, "NONE_2")) { 241 250 if (out_bitpix == 8) return (1); 242 251 if (out_bitpix == 16) return (1); -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c
r38366 r38399 262 262 int k; 263 263 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, " "); } 265 265 fprintf (stderr, "\n"); 266 266 } … … 279 279 int k; 280 280 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, " "); } 282 282 fprintf (stderr, "\n"); 283 283 } 284 284 285 if (strcasecmp(cmptype, "NONE") && 286 strcasecmp(cmptype, "NONE_2") && 285 if (strcasecmp(cmptype, "NONE_2") && // strcasecmp(cmptype, "NONE") && 287 286 strcasecmp(cmptype, "GZIP_1") && 288 287 strcasecmp(cmptype, "GZIP_2") && … … 296 295 int k; 297 296 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, " "); } 299 298 fprintf (stderr, "\n"); 300 299 fprintf (stderr, "Nout : %d -> ", Nout); … … 310 309 fprintf (stderr, "%d\n", Nout); 311 310 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, " "); } 313 312 fprintf (stderr, "\n"); 314 313 } … … 322 321 int k; 323 322 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, " "); } 325 324 fprintf (stderr, "\n"); 326 325 } … … 336 335 int k; 337 336 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, " "); } 339 338 fprintf (stderr, "\n"); 340 339 } … … 404 403 int offset = 0; 405 404 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) { \ 409 408 TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)]; \ 410 409 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 412 411 *TILEptr = oblank; \ 413 412 } else { \ 414 *TILEptr = *RAWptr * zscale + zzero; \ 413 *TILEptr = directCopy ? *RAWptr : *RAWptr * zscale + zzero; \ 414 fprintf (stderr, "dis: %08x : %08x\n", *TILEptr, *RAWptr); \ 415 415 } } } 416 416 417 417 // we need to set up switches for all of the possible combinations: 418 418 // 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)]; \ 421 435 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ 422 436 if (!isfinite(*TILEptr)) { \ 423 437 *TILEptr = oblank; \ 424 438 } else { \ 425 *TILEptr = *RAWptr * zscale + zzero; \ 426 } } } 439 if (directCopy) { \ 440 *TILEptr = *RAWptr; \ 441 } else { \ 442 *TILEptr = *RAWptr * zscale + zzero; \ 443 } } } } 427 444 428 445 // 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) { \ 430 459 TYPE *RAWptr = (TYPE *) &raw[i*SIZE*Ztile[0]]; \ 431 460 switch (matrix->bitpix) { \ 432 461 case 8: SCALE_AND_DIST_INT (char, 1); break; \ 433 462 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; \ 435 464 case -32: SCALE_AND_DIST_FLOAT (float, 4); break; \ 436 465 case -64: SCALE_AND_DIST_FLOAT (double, 8); break; \ … … 534 563 char *srcptr = &matrix->buffer[size*(offset + start) + k]; 535 564 # endif 536 char *rawptr = &raw[i* size*Ztile[0] + k*Nraw];565 char *rawptr = &raw[i*Ztile[0] + k*Nraw]; 537 566 for (j = 0; j < Ztile[0]; j++, srcptr += size, rawptr ++) { 538 567 if (FALSE && (i == 0) && (j < 4) && (pass == 0)) { -
branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c
r38366 r38399 78 78 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE; 79 79 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 81 81 strcpy (fields[i].zctype, zcmptype); 82 82 … … 127 127 fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize; 128 128 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 129 150 130 151 // RICE can only be used on integer fields -
branches/eam_branches/ohana.20150429/src/libfits/test/imagecomp.c
r38366 r38399 4 4 5 5 int test_compress (int bitpix, char *zcmptype); 6 int test_compress_fullrange (int bitpix, char *zcmptype); 7 int test_compress_fulltile (int bitpix, char *zcmptype); 6 8 7 9 // char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "PLIO_1", "RICE_1", "RICE_ONE", "HCOMPRESS_1", NULL}; … … 9 11 int bitpix[] = {8, 16, 32, -32, -64, 0}; 10 12 13 // char *cmptype[] = {"NONE_2", NULL}; 14 // int bitpix[] = {16, 0}; 15 16 static int NX = 10; 17 static int NY = 10; 18 11 19 int main (int argc, char **argv) { 12 20 13 plan_tests ( 64);21 plan_tests (3*3*234); 14 22 15 23 diag ("libfits imagecomp.c tests"); … … 21 29 if (!strcasecmp (cmptype[i], "RICE_ONE") && (bitpix[j] < 0)) continue; 22 30 test_compress (bitpix[j], cmptype[i]); 31 test_compress_fulltile (bitpix[j], cmptype[i]); 32 test_compress_fullrange (bitpix[j], cmptype[i]); 23 33 } 24 34 } 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(); 26 58 } 27 28 # define NX 1029 # define NY 1030 59 31 60 int test_compress (int bitpix, char *zcmptype) { // make a table, compress, uncompress, compare : use compression zcmptype … … 77 106 } 78 107 108 // int Ztile[2] = {NX, NY}; 109 // ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, (int *) &Ztile, zcmptype), "compressed image"); 79 110 ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, NULL, zcmptype), "compressed image"); 80 81 111 ok (gfits_uncompress_image (&outheader, &outmatrix, &ftable), "uncompressed image"); 82 112 … … 115 145 } 116 146 147 int 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 234 int 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 8 8 int main (int argc, char **argv) { 9 9 10 plan_tests (64); 10 plan_tests (45); 11 12 diag ("libfits ricetest.c tests"); 11 13 12 14 // buffers to store max array … … 14 16 char cmpdata[NBYTE]; 15 17 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 } 16 44 17 45 if (1) { … … 27 55 28 56 int Ncmp = fits_rcomp_short (rawvalue, NPIX, cmpdata, NBYTE, 32); 29 fprintf (stderr, "Ncmp: %d\n", Ncmp);57 ok (Ncmp > 0, "compressed short data"); 30 58 31 59 int status = fits_rdecomp_short (cmpdata, Ncmp, outdata, NPIX, 32); 32 fprintf (stderr, "status: %d\n", status);60 ok (!status, "decompressed short data"); 33 61 34 62 int Nbad = 0; … … 41 69 } 42 70 43 if ( 0) {71 if (1) { 44 72 int *rawvalue = (int *) rawdata; 45 73 int *outvalue = (int *) outdata; … … 53 81 54 82 int Ncmp = fits_rcomp (rawvalue, NPIX, cmpdata, NBYTE, 32); 55 fprintf (stderr, "Ncmp: %d\n", Ncmp);83 ok (Ncmp > 0, "compressed int data"); 56 84 57 85 int status = fits_rdecomp (cmpdata, Ncmp, outdata, NPIX, 32); 58 fprintf (stderr, "status: %d\n", status);86 ok (!status, "decompressed int data"); 59 87 60 88 int Nbad = 0; … … 62 90 if (rawvalue[i] != outvalue[i]) Nbad ++; 63 91 } 64 65 92 ok (!Nbad, "values match"); 66 93 } 67 94 } 68 exit (0);95 return exit_status(); 69 96 } -
branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c
r38366 r38399 4 4 5 5 int test_compress (char *zcmptype); 6 int test_compress_fullrange (char *zcmptype); 6 7 int test_compress_single_full (char *zcmptype); 7 8 9 char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "RICE_1", "RICE_ONE", "AUTO", NULL}; 10 8 11 int main (int argc, char **argv) { 9 12 10 plan_tests ( 64);13 plan_tests (286); 11 14 12 15 diag ("libfits tablecomp.c tests"); 13 16 14 test_compress_single_full ("GZIP_1");15 test_compress_single_full ("RICE_1");16 17 17 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(); 26 42 } 27 43 … … 37 53 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 38 54 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"); 44 61 45 62 // generate the output array that carries the data … … 47 64 48 65 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); 54 72 55 73 int i; 56 74 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; 62 81 } 63 82 64 83 // 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"); 70 90 71 91 Header *outheader = &header; … … 94 114 off_t Nrow; 95 115 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"); 101 122 102 123 // 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)"); 121 150 122 151 gfits_free_header (&header); … … 129 158 } 130 159 131 int test_compress_ single_full(char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"160 int test_compress_fullrange (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 132 161 133 162 Header header; … … 140 169 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 141 170 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"); 143 177 144 178 // generate the output array that carries the data … … 146 180 147 181 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 150 192 int i; 151 193 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); 153 200 } 154 201 155 202 // 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"); 157 209 158 210 Header *outheader = &header; … … 163 215 FTable cmptable; 164 216 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"); 166 218 167 219 Header rawheader; … … 181 233 off_t Nrow; 182 234 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 275 int 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 183 327 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"); 184 328 -
branches/eam_branches/ohana.20150429/src/libfits/test/zlib.c
r38334 r38399 41 41 } 42 42 43 # ifdef VERBOSE 43 44 char *rawdata = (char *) srcbuf; 44 45 fprintf (stderr, "inp: "); … … 47 48 } 48 49 fprintf (stderr, "\n"); 50 # endif 49 51 50 52 // the '5' is the compression level: make this a user argument 51 53 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); 53 55 if (err != Z_OK) { fprintf (stderr, "error 1: %d vs %d\n", err, Z_OK); exit (1); } 54 56 55 57 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); 57 59 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); 59 61 60 62 // dump out the data which failed to uncompress (and the input data) 63 # ifdef VERBOSE 61 64 char *cmpdata = (char *) tgtbuf; 62 65 fprintf (stderr, "out: "); … … 65 68 } 66 69 fprintf (stderr, "\n"); 70 # endif 67 71 68 72 assert (zdn.total_out <= NTGT*sizeof(double)); 69 73 70 fprintf (stderr, "result: %d bytes\n", (int) zdn.total_out);74 // fprintf (stderr, "result: %d bytes\n", (int) zdn.total_out); 71 75 // for (i = 0; i < zdn.total_out / sizeof(double); i++) { 72 76 // fprintf (stderr, "%d : 0x%02hhx\n", i, tgtbuf[i]); … … 87 91 // the '5' is the compression level: make this a user argument 88 92 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); 90 94 if (err != Z_OK) { fprintf (stderr, "error 1: %d vs %d\n", err, Z_OK); exit (1); } 91 95 92 96 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); 94 98 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); 96 100 101 # ifdef VERBOSE 97 102 char *outdata = (char *) outbuf; 98 103 fprintf (stderr, "unc: "); … … 101 106 } 102 107 fprintf (stderr, "\n"); 108 # endif 103 109 104 110 assert (zup.total_out <= NTGT*sizeof(double)); 105 111 106 fprintf (stderr, "result: %d bytes\n", (int) zup.total_out);112 // fprintf (stderr, "result: %d bytes\n", (int) zup.total_out); 107 113 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]); 109 115 assert (outbuf[i] == srcbuf[i]); 110 116 } 111 117 } 112 113 exit (0); 118 return exit_status(); 114 119 } 115 120 … … 175 180 } 176 181 } 177 178 exit (0); 182 return exit_status(); 179 183 }
Note:
See TracChangeset
for help on using the changeset viewer.
