Changeset 39457 for trunk/Ohana/src/libfits/matrix/F_compress_M.c
- Timestamp:
- Mar 11, 2016, 10:23:42 PM (10 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/libfits/matrix/F_compress_M.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/ohana.20160226 merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/libfits/matrix/F_compress_M.c
r38441 r39457 4 4 # define VERBOSE_DUMP 0 5 5 6 int gfits_collect_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank,int *ztile, int zblank, float zscale, float zzero);6 int gfits_collect_gzp2 (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero); 7 7 8 8 // the user needs to specify the various compression options: … … 23 23 # define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; } 24 24 25 int gfits_compress_image (Header *header, Matrix *matrix, FTable *ftable, int *Ztile, char *zcmptype) {25 int gfits_compress_image (Header *header, Matrix *matrix, FTable *ftable, unsigned long int *Ztile, char *zcmptype) { 26 26 27 27 int i; … … 33 33 char *zdata = NULL; 34 34 35 int *ztile = Ztile;35 unsigned long int *ztile = Ztile; 36 36 37 37 Header *theader = ftable->header; … … 41 41 // determine the number of tiles (from ztile[] and image size) 42 42 if (!ztile) { 43 ALLOCATE (ztile, int, matrix->Naxes);43 ALLOCATE (ztile, unsigned long int, matrix->Naxes); 44 44 ztile[0] = matrix->Naxis[0]; 45 45 for (i = 1; i < matrix->Naxes; i++) ztile[i] = 1; … … 99 99 for (i = 0; i < header->Naxes; i++) { 100 100 snprintf (keyword, 10, "ZTILE%d", i + 1); 101 if (!gfits_modify (theader, keyword, "% d", 1, ztile[i])) ESCAPE;101 if (!gfits_modify (theader, keyword, "%lu", 1, ztile[i])) ESCAPE; 102 102 } 103 103 … … 157 157 158 158 // size (in pixels) of the largest tile 159 int max_tile_size = gfits_imtile_maxsize (matrix, ztile);159 unsigned long int max_tile_size = gfits_imtile_maxsize (matrix, ztile); 160 160 161 161 // size of a pixel in the raw pixel buffer (before compression) … … 179 179 180 180 // allocate the buffer for compression work 181 int Nzdata_alloc = raw_pixsize*max_tile_size + 100;181 unsigned long int Nzdata_alloc = raw_pixsize*max_tile_size + 100; 182 182 ALLOCATE (raw, char, raw_pixsize*max_tile_size); 183 183 ALLOCATE (zdata, char, Nzdata_alloc); … … 191 191 192 192 // size of the current tile in pixels 193 int Nraw = gfits_tile_size (matrix, otile, ztile);193 unsigned long int Nraw = gfits_tile_size (matrix, otile, ztile); 194 194 195 195 // copy the raw pixels from their native matrix locations to the temporary output buffer … … 216 216 if (!gfits_byteswap_zdata (raw, Nraw * raw_pixsize, raw_pixsize)) ESCAPE; 217 217 } 218 int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression218 unsigned long int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression 219 219 220 220 if (VERBOSE_DUMP && (i == 0)) { … … 223 223 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", raw[k]); if (k % 4 == 3) fprintf (stderr, " "); } 224 224 fprintf (stderr, "\n"); 225 fprintf (stderr, "Nzdata: % d-> ", Nzdata);225 fprintf (stderr, "Nzdata: %lu -> ", Nzdata); 226 226 } 227 227 … … 231 231 if (VERBOSE_DUMP && (i == 0)) { 232 232 int k; 233 fprintf (stderr, "% d\n", Nzdata);233 fprintf (stderr, "%lu\n", Nzdata); 234 234 fprintf (stderr, "cmp SWP: "); 235 235 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); } … … 290 290 291 291 int gfits_copy_keywords_compress (Header *srchead, Header *tgthead) { 292 292 OHANA_UNUSED_PARAM(tgthead); 293 OHANA_UNUSED_PARAM(srchead); 294 295 # if (0) 293 296 int i; 294 297 295 298 for (i = 0; i < srchead->datasize; i += FT_LINE_LENGTH) { 296 299 } 300 # endif 301 297 302 return TRUE; 298 303 } … … 303 308 // * ztile gives the size of the i-th dimension of the current tile 304 309 // * raw_bitpix defines the size and type of the raw buffer 305 int gfits_collect_data (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank,int *ztile, int zblank, float zscale, float zzero) {306 307 int i, j, start, offset, coord, Nline;308 int *counter = NULL;309 int *Ztile = NULL;310 311 ALLOCATE (counter, int, matrix->Naxes); // counter for current row in tile to copy312 ALLOCATE (Ztile, int, matrix->Naxes); // true sizes of this tile (in pixels)310 int gfits_collect_data (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) { 311 312 int i, k, start, offset, coord, Nline; 313 unsigned int *counter = NULL; 314 unsigned long int *Ztile = NULL; 315 316 ALLOCATE (counter, unsigned int, matrix->Naxes); // counter for current row in tile to copy 317 ALLOCATE (Ztile, unsigned long int, matrix->Naxes); // true sizes of this tile (in pixels) 313 318 314 319 for (i = 0; i < matrix->Naxes; i++) { … … 343 348 // this macro is used at the inner switch to run the actual loop 344 349 # define SCALE_AND_DIST_INT_PRINT(TYPE, SIZE, INTYPE) { \ 350 unsigned long int j; \ 345 351 TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)]; \ 346 352 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 356 362 // this macro is used at the inner switch to run the actual loop 357 363 # define SCALE_AND_DIST_INT(OTYPE, OSIZE) { \ 364 unsigned long int j; \ 358 365 OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \ 359 366 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 370 377 // this macro is used at the inner switch to run the actual loop 371 378 # define SCALE_AND_DIST_FLOAT(OTYPE, OSIZE) { \ 379 unsigned long int j; \ 372 380 OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \ 373 381 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 419 427 420 428 // update the counters, carrying to the next dimension if needed 421 for ( j = 1; j < matrix->Naxes; j++) {422 counter[ j] ++;423 if (counter[ j] == Ztile[j]) {424 counter[ j] = 0;429 for (k = 1; k < matrix->Naxes; k++) { 430 counter[k] ++; 431 if (counter[k] == Ztile[k]) { 432 counter[k] = 0; 425 433 } else { 426 434 break; 427 435 } 428 436 } 429 if ( j== matrix->Naxes) assert (i == Nline - 1); // we should be done here...437 if (k == matrix->Naxes) assert (i == Nline - 1); // we should be done here... 430 438 431 439 // Naxes = 3 … … 435 443 // determine the offset of the next line relative to the start position 436 444 offset = counter[matrix->Naxes - 1]; 437 for ( j = matrix->Naxes - 2; j >= 0; j--) {438 offset = offset*matrix->Naxis[ j] + counter[j];445 for (k = matrix->Naxes - 2; k >= 0; k--) { 446 offset = offset*matrix->Naxis[k] + counter[k]; 439 447 } 440 448 } … … 453 461 // * ztile gives the size of the i-th dimension of the current tile 454 462 // * raw_bitpix defines the size and type of the raw buffer 455 int gfits_collect_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) { 456 457 int i, j, k; 458 int *counter = NULL; 459 int *Ztile = NULL; 460 461 ALLOCATE (counter, int, matrix->Naxes); // counter for current row in tile to copy 462 ALLOCATE (Ztile, int, matrix->Naxes); // true sizes of this tile (in pixels) 463 int gfits_collect_gzp2 (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) { 464 OHANA_UNUSED_PARAM(oblank); 465 OHANA_UNUSED_PARAM(zblank); 466 OHANA_UNUSED_PARAM(zzero); 467 OHANA_UNUSED_PARAM(zscale); 468 469 unsigned long int i, j; 470 unsigned int *counter = NULL; 471 unsigned long int *Ztile = NULL; 472 473 ALLOCATE (counter, unsigned int, matrix->Naxes); // counter for current row in tile to copy 474 ALLOCATE (Ztile, unsigned long int, matrix->Naxes); // true sizes of this tile (in pixels) 463 475 464 for (i = 0; i < matrix->Naxes; i++) { 465 counter[i] = 0; 466 Ztile[i] = MIN ((matrix->Naxis[i] - otile[i]*ztile[i]), ztile[i]); 476 int k; 477 for (k = 0; k < matrix->Naxes; k++) { 478 counter[k] = 0; 479 Ztile[k] = MIN ((matrix->Naxis[k] - otile[k]*ztile[k]), ztile[k]); 467 480 } 468 481 469 482 // number of lines in the tile (in pixels) 470 int Nline = 1;471 int Npix = matrix->Naxis[0];472 for ( i = 1; i < matrix->Naxes; i++) {473 Nline *= Ztile[ i];474 Npix *= matrix->Naxis[ i];483 unsigned long int Nline = 1; 484 unsigned long int Npix = matrix->Naxis[0]; 485 for (k = 1; k < matrix->Naxes; k++) { 486 Nline *= Ztile[k]; 487 Npix *= matrix->Naxis[k]; 475 488 } 476 489 … … 482 495 // start = otile[0]*ztile[0] + Naxis[0]*(otile[1]*ztile[1] + Naxis[1]*(otile[2]*ztile[2] + ...)); 483 496 int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1]; 484 for ( i = matrix->Naxes - 2; i >= 0; i--) {485 int coord = otile[i]*ztile[i];486 start = start*matrix->Naxis[ i] + coord;497 for (k = matrix->Naxes - 2; k >= 0; k--) { 498 unsigned long int coord = otile[k]*ztile[k]; 499 start = start*matrix->Naxis[k] + coord; 487 500 } 488 501 … … 519 532 520 533 // update the counters, carrying to the next dimension if needed 521 for (j = 1; j < matrix->Naxes; j++) { 522 counter[j] ++; 523 if (counter[j] == Ztile[j]) { 524 counter[j] = 0; 534 int axis; 535 for (axis = 1; axis < matrix->Naxes; axis++) { 536 counter[axis] ++; 537 if (counter[axis] == Ztile[axis]) { 538 counter[axis] = 0; 525 539 } else { 526 540 break; 527 541 } 528 542 } 529 if ( j== matrix->Naxes) assert (i == Nline - 1); // we should be done here...543 if (axis == matrix->Naxes) assert (i == Nline - 1); // we should be done here... 530 544 531 545 // Naxes = 3 … … 535 549 // determine the offset of the next line relative to the start position 536 550 offset = counter[matrix->Naxes - 1]; 537 for ( j = matrix->Naxes - 2; j >= 0; j--) {538 offset = offset*matrix->Naxis[ j] + counter[j];551 for (axis = matrix->Naxes - 2; axis >= 0; axis--) { 552 offset = offset*matrix->Naxis[axis] + counter[axis]; 539 553 } 540 554 }
Note:
See TracChangeset
for help on using the changeset viewer.
