Changeset 39457 for trunk/Ohana/src/libfits
- Timestamp:
- Mar 11, 2016, 10:23:42 PM (10 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 21 edited
- 1 copied
-
. (modified) (1 prop)
-
src/libfits/extern/gzip.c (modified) (6 diffs)
-
src/libfits/header/F_write_H.c (modified) (1 diff)
-
src/libfits/include/gfits_compress.h (copied) (copied from branches/eam_branches/ohana.20160226/src/libfits/include/gfits_compress.h )
-
src/libfits/include/gfitsio.h (modified) (2 diffs)
-
src/libfits/matrix/F_compress_M.c (modified) (22 diffs)
-
src/libfits/matrix/F_compress_data.c (modified) (7 diffs)
-
src/libfits/matrix/F_compress_utils.c (modified) (7 diffs)
-
src/libfits/matrix/F_convert_format.c (modified) (3 diffs)
-
src/libfits/matrix/F_uncompress_M.c (modified) (27 diffs)
-
src/libfits/matrix/F_uncompress_data.c (modified) (6 diffs)
-
src/libfits/table/F_compress_T.c (modified) (28 diffs)
-
src/libfits/table/F_set_column.c (modified) (4 diffs)
-
src/libfits/table/F_table_varlength.c (modified) (1 diff)
-
src/libfits/table/F_uncompress_T.c (modified) (20 diffs)
-
src/libfits/table/F_write_T.c (modified) (1 diff)
-
src/libfits/table/F_write_TH.c (modified) (1 diff)
-
src/libfits/test/imagecomp.c (modified) (2 diffs)
-
src/libfits/test/keywords.c (modified) (6 diffs)
-
src/libfits/test/ricetest.c (modified) (5 diffs)
-
src/libfits/test/tablecomp.c (modified) (12 diffs)
-
src/libfits/test/zlib.c (modified) (5 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/extern/gzip.c
r38986 r39457 122 122 123 123 z_stream stream; 124 int i,err;124 int err; 125 125 126 126 stream.next_in = (Bytef*)source; … … 140 140 if (EXTRA_VERBOSE) { 141 141 fprintf (stderr, "inp cmp: "); 142 unsigned long int i; 142 143 for (i = 0; i < sourceLen; i++) { 143 144 fprintf (stderr, "0x%02hhx ", source[i]); … … 165 166 if (EXTRA_VERBOSE) { 166 167 fprintf (stderr, "out cmp: "); 168 unsigned long int i; 167 169 for (i = 0; i < stream.total_out; i++) { 168 170 fprintf (stderr, "0x%02hhx ", dest[i]); … … 182 184 183 185 z_stream stream; 184 int i,err;186 int err; 185 187 186 188 stream.next_in = (Bytef*)source; … … 200 202 if (EXTRA_VERBOSE) { 201 203 fprintf (stderr, "inp unc: "); 204 unsigned long int i; 202 205 for (i = 0; i < sourceLen; i++) { 203 206 fprintf (stderr, "0x%02hhx ", source[i]); … … 226 229 if (EXTRA_VERBOSE) { 227 230 fprintf (stderr, "out unc: "); 231 unsigned long int i; 228 232 for (i = 0; i < stream.total_out; i++) { 229 233 fprintf (stderr, "0x%02hhx ", dest[i]); -
trunk/Ohana/src/libfits/header/F_write_H.c
r38553 r39457 25 25 myAssert (myBlock->startblock == OHANA_MEMMAGIC, "bad memory"); 26 26 myAssert (myBlock->endblock == OHANA_MEMMAGIC, "bad memory"); 27 myAssert (myBlock->size >= header[0].datasize, "overflow");27 myAssert (myBlock->size >= (size_t) header[0].datasize, "overflow"); 28 28 } 29 29 # endif -
trunk/Ohana/src/libfits/include/gfitsio.h
r39394 r39457 193 193 194 194 int gfits_uncompress_image PROTO((Header *header, Matrix *matrix, FTable *ftable)); 195 int gfits_uncompress_data PROTO((char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout,int Nout_alloc, int out_pixsize));196 int gfits_distribute_data PROTO((Matrix *matrix, char *data, int Ndata, int bitpix, int *otile, int oblank,int *ztile, int zblank, float zscale, float zzero));197 198 int gfits_compress_data PROTO((char *zdata, int *Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *rawdata,int Nraw, int raw_pixsize, int Nx, int Ny));199 int gfits_compress_image PROTO((Header *header, Matrix *matrix, FTable *ftable, int *Ztile, char *zcmptype));200 int gfits_collect_data PROTO((Matrix *matrix, char *raw, int Nraw, int raw_pixsize, int *otile, int oblank,int *ztile, int zblank, float zscale, float zzero));195 int gfits_uncompress_data PROTO((char *zdata, unsigned long int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, unsigned long int *Nout, unsigned long int Nout_alloc, int out_pixsize)); 196 int gfits_distribute_data PROTO((Matrix *matrix, char *data, unsigned long int Ndata, int bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero)); 197 198 int gfits_compress_data PROTO((char *zdata, unsigned long int *Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *rawdata, unsigned long int Nraw, int raw_pixsize, int Nx, int Ny)); 199 int gfits_compress_image PROTO((Header *header, Matrix *matrix, FTable *ftable, unsigned long int *Ztile, char *zcmptype)); 200 int gfits_collect_data PROTO((Matrix *matrix, char *raw, unsigned long int Nraw, int raw_pixsize, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero)); 201 201 202 202 int gfits_copy_keywords_compress PROTO((Header *srchead, Header *tgthead)); 203 203 int gfits_swap_raw PROTO((Matrix *matrix)); 204 204 205 off_t gfits_tile_size PROTO((Matrix *matrix, int *otile, int *ztile));206 int gfits_imtile_maxsize PROTO((Matrix *matrix, int *ztile));207 int gfits_imtile_count PROTO((Matrix *matrix, int *ztile, int *ntile));205 off_t gfits_tile_size PROTO((Matrix *matrix, int *otile, unsigned long int *ztile)); 206 int gfits_imtile_maxsize PROTO((Matrix *matrix, unsigned long int *ztile)); 207 int gfits_imtile_count PROTO((Matrix *matrix, unsigned long int *ztile, int *ntile)); 208 208 int gfits_imtile_start PROTO((Matrix *matrix, int *otile)); 209 int gfits_imtile_next PROTO((Matrix *matrix, int *ztile, int *ntile, int *otile));209 int gfits_imtile_next PROTO((Matrix *matrix, unsigned long int *ztile, int *ntile, int *otile)); 210 210 211 211 int gfits_extension_is_compressed_image PROTO((Header *header)); 212 212 int gfits_extension_is_compressed_table PROTO((Header *header)); 213 int gfits_byteswap_zdata PROTO((char *zdata, int Nzdata, int pixsize));213 int gfits_byteswap_zdata PROTO((char *zdata, off_t Nzdata, int pixsize)); 214 214 int gfits_compressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions)); 215 215 int gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions)); … … 279 279 int gfits_write_Theader PROTO((char *filename, Header *header)); 280 280 281 int gfits_compress_table PROTO((FTable *srctable, FTable *tgttable, int ztilelen, char *zcmptype));281 int gfits_compress_table PROTO((FTable *srctable, FTable *tgttable, unsigned long int ztilelen, char *zcmptype)); 282 282 int gfits_uncompress_table PROTO((FTable *srctable, FTable *tgttable)); 283 283 -
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 } -
trunk/Ohana/src/libfits/matrix/F_compress_data.c
r38986 r39457 2 2 # include <gfitsio.h> 3 3 # include <zlib.h> 4 5 /* functions defined in ricecomp.c */ 6 int fits_rcomp(int a[], int nx, unsigned char *c, int clen, int nblock); 7 int fits_rcomp_short(short a[], int nx, unsigned char *c, int clen, int nblock); 8 int fits_rcomp_byte(char a[], int nx, unsigned char *c, int clen, int nblock); 9 int fits_rdecomp (unsigned char *c, int clen, unsigned int array[], int nx, int nblock); 10 int fits_rdecomp_short (unsigned char *c, int clen, unsigned short array[], int nx, int nblock); 11 int fits_rdecomp_byte (unsigned char *c, int clen, unsigned char array[], int nx, int nblock); 12 13 /* functions defined in fits_hcompress.c */ 14 # define LONGLONG long long 15 int fits_hcompress(int *a, int ny, int nx, int scale, char *output, long *nbytes, int *status); 16 int fits_hcompress64(LONGLONG *a, int ny, int nx, int scale, char *output, long *nbytes, int *status); 17 18 /* functions defined in fits_hdeccompress.c */ 19 int fits_hdecompress(unsigned char *input, int smooth, int *a, int *ny, int *nx, int *scale, int *status); 20 int fits_hdecompress64(unsigned char *input, int smooth, LONGLONG *a, int *ny, int *nx, int *scale, int *status); 21 22 /* functions defined in pliocomp.c */ 23 int pl_p2li (int *pxsrc, int xs, short *lldst, int npix); 24 int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix); 25 26 /* functions defined in gzip.c */ 27 int gfits_gz_stripheader (unsigned char *data, int *ndata); 28 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 29 int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 4 # include <gfits_compress.h> 30 5 31 6 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } … … 33 8 // XXX I'm putting Nx and Ny on the argument list -- only used by hcompress 34 9 // with a little work, these could go on the option list 35 int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype, 36 char **optname, char **optvalue, int Nopt, 37 char *rawdata, int Nrawpix, int rawpix_size, 38 int Nx, int Ny) { 10 int gfits_compress_data (char *zdata, unsigned long int *Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *rawdata, unsigned long int Nrawpix, int rawpix_size, int Nx, int Ny) { 39 11 40 int Nout;41 12 int status; 42 13 … … 68 39 69 40 if (!strcasecmp(cmptype, "RICE_1") || !strcasecmp(cmptype, "RICE_ONE")) { 41 long int Nout; 70 42 int i, blocksize; 71 43 // look for the BLOCKSIZE … … 85 57 // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum); 86 58 87 int k;88 89 59 switch (rawpix_size) { 90 60 case 4: … … 98 68 99 69 if (0) { 100 fprintf (stderr, "Nout: %d, Nrawpix: %d\n", Nout, Nrawpix); 70 long int k; 71 fprintf (stderr, "Nout: %lu, Nrawpix: %lu\n", Nout, Nrawpix); 101 72 fprintf (stderr, "cmp inp: "); 102 73 for (k = 0; k < Nout; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 2) fprintf (stderr, " "); } … … 119 90 return (FALSE); 120 91 } 121 if (Nout > *Nzdata) {122 fprintf (stderr, "buffer overrun! % d out, %davailable\n", Nout, *Nzdata);92 if (Nout > (long int) *Nzdata) { 93 fprintf (stderr, "buffer overrun! %ld out, %lu available\n", Nout, *Nzdata); 123 94 return FALSE; 124 95 } 125 *Nzdata = Nout;96 *Nzdata = (unsigned long int) Nout; 126 97 return TRUE; 127 98 } … … 129 100 if (!strcasecmp(cmptype, "PLIO_1")) { 130 101 // note the fortan starting point: zdata is decremented at start 131 Nout = pl_p2li ((int *) rawdata, 1, (short *) zdata, Nrawpix);102 int Nout = pl_p2li ((int *) rawdata, 1, (short *) zdata, Nrawpix); 132 103 *Nzdata = Nout; 133 104 if (!Nout) return (FALSE); -
trunk/Ohana/src/libfits/matrix/F_compress_utils.c
r38441 r39457 17 17 18 18 typedef struct { 19 int *ztile; // max size of a tile (edge tiles may be smaller)19 unsigned long int *ztile; // max size of a tile (edge tiles may be smaller) 20 20 int *otile; // counter for current tile (eg, for (2,3,0) otile[0] = 2, otile[1] = 3, otile[2] = 0) 21 21 int *ntile; // number of tiles in dimension [i] … … 23 23 24 24 // advance the otile counter. 25 int gfits_imtile_next (Matrix *matrix, int *ztile, int *ntile, int *otile) { 25 int gfits_imtile_next (Matrix *matrix, unsigned long int *ztile, int *ntile, int *otile) { 26 OHANA_UNUSED_PARAM(ztile); 26 27 27 28 int i; … … 53 54 54 55 // how many tiles needed for this image (given ztile[]) 55 int gfits_imtile_count (Matrix *matrix, int *ztile, int *ntile) {56 int gfits_imtile_count (Matrix *matrix, unsigned long int *ztile, int *ntile) { 56 57 57 58 int i; … … 67 68 68 69 // how many tiles needed for this image (given ztile[]) 69 int gfits_imtile_maxsize (Matrix *matrix, int *ztile) {70 int gfits_imtile_maxsize (Matrix *matrix, unsigned long int *ztile) { 70 71 71 72 int i; 72 73 73 int max_tile_size = 1;74 unsigned long int max_tile_size = 1; 74 75 for (i = 0; i < matrix->Naxes; i++) { 75 76 max_tile_size *= ztile[i]; … … 80 81 81 82 // true sizes of this tile (in pixels) 82 off_t gfits_tile_size (Matrix *matrix, int *otile, int *ztile) {83 off_t gfits_tile_size (Matrix *matrix, int *otile, unsigned long int *ztile) { 83 84 84 85 off_t i, Npixels, Ndimen; … … 93 94 } 94 95 95 int gfits_byteswap_zdata (char *zdata, int Nzdata, int pixsize) {96 int gfits_byteswap_zdata (char *zdata, off_t Nzdata, int pixsize) { 96 97 97 98 # define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; } … … 99 100 # ifdef BYTE_SWAP 100 101 101 int i;102 off_t i; 102 103 103 104 // fprintf (stderr, "swapping %d bytes in pix of size %d bytes...\n", Nzdata, pixsize); -
trunk/Ohana/src/libfits/matrix/F_convert_format.c
r38062 r39457 19 19 in = (inMode *) matrix[0].buffer; \ 20 20 for (i = 0; i < Npixels; i++, out++, in++) \ 21 if (*in == inBlank) {\21 if (*in == (inMode) inBlank) { \ 22 22 *out = (MY_NAN); \ 23 23 } else { \ … … 32 32 in = (inMode *) matrix[0].buffer; \ 33 33 for (i = 0; i < Npixels; i++, out++, in++) \ 34 if (*in == inBlank) { \34 if (*in == (inMode) inBlank) { \ 35 35 *out = (MY_NAN); \ 36 36 } else { \ … … 45 45 in = (inMode *)matrix[0].buffer + Npixels - 1; \ 46 46 for (i = 0; i < Npixels; i++, out--, in--) \ 47 if (*in == inBlank) { \47 if (*in == (inMode) inBlank) { \ 48 48 *out = (MY_NAN); \ 49 49 } else { \ -
trunk/Ohana/src/libfits/matrix/F_uncompress_M.c
r38989 r39457 4 4 # define VERBOSE_DUMP 0 5 5 6 int gfits_distribute_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero); 7 8 # define ESCAPE { \ 9 fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); \ 10 if (ztile != NULL) free (ztile); \ 11 if (optname != NULL) { \ 12 for (j = 0; j < Noptions; j++) { \ 13 free (optname[j]); \ 14 free (optvalue[j]); \ 15 } \ 16 free (optname); \ 17 free (optvalue); \ 18 } \ 19 if (out != NULL) free (out); \ 20 if (otile != NULL) free (otile); \ 21 if (ntile != NULL) free (ntile); \ 22 return (FALSE); } 23 24 # define MOD_KEYWORD(ZNAME,NAME,TYPE,IN,OUT) { \ 6 int gfits_distribute_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 8 # define ESCAPE { \ 9 fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); \ 10 if (ztile != NULL) free (ztile); \ 11 if (optname != NULL) { \ 12 int opt; \ 13 for (opt = 0; opt < Noptions; opt++) { \ 14 free (optname[opt]); \ 15 free (optvalue[opt]); \ 16 } \ 17 free (optname); \ 18 free (optvalue); \ 19 } \ 20 if (out != NULL) free (out); \ 21 if (otile != NULL) free (otile); \ 22 if (ntile != NULL) free (ntile); \ 23 return (FALSE); } 24 25 # define MOD_KEYWORD(ZNAME,NAME,TYPE,IN,OUT) { \ 25 26 if (gfits_scan (header, ZNAME, TYPE, 1, IN)) { \ 26 gfits_modify (header, NAME, TYPE, 1, OUT); \27 } \27 gfits_modify (header, NAME, TYPE, 1, OUT); \ 28 } \ 28 29 gfits_delete (header, ZNAME, 1); } 29 30 30 # define MOD_KEYWORD_ALT(ZNAME,NAME,TYPE,IN,OUT) { \31 # define MOD_KEYWORD_ALT(ZNAME,NAME,TYPE,IN,OUT) { \ 31 32 if (gfits_scan_alt (header, ZNAME, TYPE, 1, IN)) { \ 32 gfits_modify_alt (header, NAME, TYPE, 1, OUT); \33 } \33 gfits_modify_alt (header, NAME, TYPE, 1, OUT); \ 34 } \ 34 35 gfits_delete (header, ZNAME, 1); } 35 36 36 # define MOD_KEYWORD_REQUIRED(ZNAME,NAME,TYPE,IN,OUT) { \37 if (!gfits_scan (header, ZNAME, TYPE, 1, IN)) ESCAPE;\38 gfits_delete (header, ZNAME, 1);\39 gfits_modify (header, NAME, TYPE, 1, OUT); }37 # define MOD_KEYWORD_REQUIRED(ZNAME,NAME,TYPE,IN,OUT) { \ 38 if (!gfits_scan (header, ZNAME, TYPE, 1, IN)) ESCAPE; \ 39 gfits_delete (header, ZNAME, 1); \ 40 gfits_modify (header, NAME, TYPE, 1, OUT); } 40 41 41 42 int gfits_uncompress_image (Header *header, Matrix *matrix, FTable *ftable) { 42 43 44 int status, zimage; 43 45 off_t Nzdata, Nzrows, zcol; 44 int i, j, status, zimage, Nout,max_tile_size;46 unsigned long int max_tile_size; 45 47 char cmptype[80]; 46 48 char zaxis[10], naxis[10], key[10], word[81], exttype[81], checksum[81], datasum[81]; … … 49 51 float zscale, zzero; 50 52 51 int *ztile = NULL;53 unsigned long int *ztile = NULL; 52 54 int *otile = NULL; 53 55 int *ntile = NULL; … … 77 79 MOD_KEYWORD_REQUIRED ("ZNAXIS", "NAXIS", "%d", &header->Naxes, header->Naxes); 78 80 79 for (i = 0; i < header->Naxes; i++) { 80 snprintf (zaxis, 10, "ZNAXIS%d", i + 1); 81 snprintf (naxis, 10, "NAXIS%d", i + 1); 82 MOD_KEYWORD_REQUIRED (zaxis, naxis, OFF_T_FMT, &header->Naxis[i], header->Naxis[i]); 81 int axis; 82 for (axis = 0; axis < header->Naxes; axis++) { 83 snprintf (zaxis, 10, "ZNAXIS%d", axis + 1); 84 snprintf (naxis, 10, "NAXIS%d", axis + 1); 85 MOD_KEYWORD_REQUIRED (zaxis, naxis, OFF_T_FMT, &header->Naxis[axis], header->Naxis[axis]); 83 86 } 84 87 … … 86 89 // the actual tile size may be smaller at the edge of a dimension. if the ZTILEn 87 90 // entries are not found, default to [Nx,1,1,...] 88 ALLOCATE (ztile, int, header->Naxes);89 if (!gfits_scan (header, "ZTILE1", "% d", 1, &ztile[0])) {91 ALLOCATE (ztile, unsigned long int, header->Naxes); 92 if (!gfits_scan (header, "ZTILE1", "%lu", 1, &ztile[0])) { 90 93 ztile[0] = header->Naxis[0]; 91 for ( i = 1; i < header->Naxes; i++) {92 ztile[ i] = 1;94 for (axis = 1; axis < header->Naxes; axis++) { 95 ztile[axis] = 1; 93 96 } 94 97 } else { 95 98 gfits_delete (header, "ZTILE1", 1); 96 for ( i = 1; i < header->Naxes; i++) {97 snprintf (key, 10, "ZTILE%d", i+ 1);98 if (!gfits_scan (header, key, "% d", 1, &ztile[i])) ESCAPE;99 for (axis = 1; axis < header->Naxes; axis++) { 100 snprintf (key, 10, "ZTILE%d", axis + 1); 101 if (!gfits_scan (header, key, "%lu", 1, &ztile[axis])) ESCAPE; 99 102 gfits_delete (header, key, 1); 100 103 } … … 199 202 // find the COMPRESSED_DATA column (format should be 1PB, 1PI, 1PJ) 200 203 // is it required that this be the only column? 201 for (i = 1; TRUE; i++) { 202 snprintf (key, 10, "TTYPE%d", i); 204 int colnum; 205 for (colnum = 1; TRUE; colnum++) { 206 snprintf (key, 10, "TTYPE%d", colnum); 203 207 if (!gfits_scan (ftable->header, key, "%s", 1, word)) ESCAPE; 204 208 if (!strcmp (word, "COMPRESSED_DATA")) break; 205 209 } 206 zcol = i;210 zcol = colnum; 207 211 208 212 if (!gfits_varlength_column_define (ftable, &zdef, zcol)) ESCAPE; … … 220 224 ALLOCATE (ntile, int, matrix->Naxes); 221 225 max_tile_size = 1; 222 for ( i = 0; i < matrix->Naxes; i++) {223 otile[ i] = 0;224 ntile[ i] = (matrix->Naxis[i] % ztile[i]) ? (matrix->Naxis[i] / ztile[i] + 1) : (matrix->Naxis[i] / ztile[i]);225 max_tile_size *= ztile[ i];226 227 // ztile[ i] is the default (or max) tile size in the i-th dimension228 // ntile[ i] is the number of tiles in the i-th dimension229 // otile[ i] is the current output tile counter in the i-th dimension226 for (axis = 0; axis < matrix->Naxes; axis++) { 227 otile[axis] = 0; 228 ntile[axis] = (matrix->Naxis[axis] % ztile[axis]) ? (matrix->Naxis[axis] / ztile[axis] + 1) : (matrix->Naxis[axis] / ztile[axis]); 229 max_tile_size *= ztile[axis]; 230 231 // ztile[axis] is the default (or max) tile size in the i-th dimension 232 // ntile[axis] is the number of tiles in the i-th dimension 233 // otile[axis] is the current output tile counter in the i-th dimension 230 234 } 231 235 … … 254 258 // fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix); 255 259 256 int Nout_alloc = raw_pixsize*max_tile_size;260 unsigned long int Nout_alloc = raw_pixsize*max_tile_size; 257 261 ALLOCATE (out, char, Nout_alloc); 258 262 … … 271 275 272 276 // expected output size for this tile 273 Nout = raw_pixsize*gfits_tile_size (matrix, otile, ztile);277 unsigned long Nout = raw_pixsize*gfits_tile_size (matrix, otile, ztile); 274 278 275 279 zdata = gfits_varlength_column_pointer (ftable, &zdef, row, &Nzdata); … … 297 301 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); } 298 302 fprintf (stderr, "\n"); 299 fprintf (stderr, "Nout : % d-> ", Nout);303 fprintf (stderr, "Nout : %lu -> ", Nout); 300 304 } 301 305 … … 307 311 if (VERBOSE_DUMP && (row == 0)) { 308 312 int k; 309 fprintf (stderr, "% d\n", Nout);313 fprintf (stderr, "%lu\n", Nout); 310 314 fprintf (stderr, "unc swp: "); 311 315 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", out[k]); if (k % 4 == 3) fprintf (stderr, " "); } … … 315 319 if (!strcasecmp(cmptype, "GZIP_1")) { 316 320 // Nout is number of pixels 317 if (!gfits_byteswap_zdata (out, Nout * raw_pixsize, raw_pixsize)) ESCAPE;321 if (!gfits_byteswap_zdata (out, (off_t) (Nout * raw_pixsize), raw_pixsize)) ESCAPE; 318 322 } 319 323 … … 340 344 341 345 // update the tile counters, carrying to the next dimension if needed 342 for ( j = 0; j < matrix->Naxes; j++) {343 otile[ j] ++;344 if (otile[ j] == ntile[j]) {345 otile[ j] = 0;346 for (axis = 0; axis < matrix->Naxes; axis++) { 347 otile[axis] ++; 348 if (otile[axis] == ntile[axis]) { 349 otile[axis] = 0; 346 350 } else { 347 351 break; … … 352 356 FREE (ztile); 353 357 if (optname != NULL) { 354 for (j = 0; j < Noptions; j++) { 355 FREE (optname[j]); 356 FREE (optvalue[j]); 358 int opt; 359 for (opt = 0; opt < Noptions; opt++) { 360 FREE (optname[opt]); 361 FREE (optvalue[opt]); 357 362 } 358 363 FREE (optname); … … 366 371 367 372 // bitpix is the input data size/type 368 int gfits_distribute_data (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank,int *ztile, int zblank, float zscale, float zzero) {369 370 int i, j;371 int *counter = NULL;372 int *Ztile = NULL;373 374 ALLOCATE (counter, int, matrix->Naxes);375 ALLOCATE (Ztile, int, matrix->Naxes);373 int gfits_distribute_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) { 374 375 int axis; 376 unsigned int *counter = NULL; 377 unsigned long int *Ztile = NULL; 378 379 ALLOCATE (counter, unsigned int, matrix->Naxes); 380 ALLOCATE (Ztile, unsigned long int, matrix->Naxes); 376 381 377 382 // counter for current row in tile to copy 378 383 // true sizes of this tile (in pixels) 379 for ( i = 0; i < matrix->Naxes; i++) {380 counter[ i] = 0;381 Ztile[ i] = MIN ((matrix->Naxis[i] - otile[i]*ztile[i]), ztile[i]);384 for (axis = 0; axis < matrix->Naxes; axis++) { 385 counter[axis] = 0; 386 Ztile[axis] = MIN ((matrix->Naxis[axis] - otile[axis]*ztile[axis]), ztile[axis]); 382 387 } 383 388 384 389 // number of lines in the tile (in pixels) 385 int Nline = 1;386 for ( i = 1; i < matrix->Naxes; i++) {387 Nline *= Ztile[ i];390 unsigned long int Nline = 1; 391 for (axis = 1; axis < matrix->Naxes; axis++) { 392 Nline *= Ztile[axis]; 388 393 } 389 394 … … 394 399 // start = otile[0]*ztile[0] + otile[1]*ztile[1]*Naxis[0] + otile[2]*ztile[2]*Naxis[0]*Naxis[1] + ...; 395 400 // start = otile[0]*ztile[0] + Naxis[0]*(otile[1]*ztile[1] + Naxis[1]*(otile[2]*ztile[2] + ...)); 396 int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1];397 for ( i = matrix->Naxes - 2; i >= 0; i--) {398 int coord = otile[i]*ztile[i];399 start = start*matrix->Naxis[ i] + coord;401 unsigned long int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1]; 402 for (axis = matrix->Naxes - 2; axis >= 0; axis--) { 403 unsigned long int coord = otile[axis]*ztile[axis]; 404 start = start*matrix->Naxis[axis] + coord; 400 405 } 401 406 402 407 // pixel offset in output array relative to tile start 403 int offset = 0;408 unsigned long int offset = 0; 404 409 405 410 int directCopy = (zzero == 0.0) && (zscale == 1.0); 406 411 407 412 # define SCALE_AND_DIST_INT_PRINT(TYPE, SIZE) { \ 413 unsigned long j; \ 408 414 TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)]; \ 409 415 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 418 424 // this macro is used at the inner switch to run the actual loop 419 425 # define SCALE_AND_DIST_INT(OTYPE, OSIZE) { \ 426 unsigned long j; \ 420 427 OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \ 421 428 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 432 439 // this macro is used at the inner switch to run the actual loop 433 440 # define SCALE_AND_DIST_FLOAT(OTYPE, OSIZE) { \ 441 unsigned long j; \ 434 442 OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \ 435 443 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ … … 461 469 case 8: SCALE_AND_DIST_INT (char, 1); break; \ 462 470 case 16: SCALE_AND_DIST_INT (short, 2); break; \ 463 case 32: SCALE_AND_DIST_INT (int, 4); break; \471 case 32: SCALE_AND_DIST_INT (int, 4); break; \ 464 472 case -32: SCALE_AND_DIST_FLOAT (float, 4); break; \ 465 473 case -64: SCALE_AND_DIST_FLOAT (double, 8); break; \ … … 468 476 469 477 // loop over lines in the tile 478 unsigned long int i; 470 479 for (i = 0; i < Nline; i++) { 471 480 switch (raw_bitpix) { … … 479 488 480 489 // update the counters, carrying to the next dimension if needed 481 for ( j = 1; j < matrix->Naxes; j++) {482 counter[ j] ++;483 if (counter[ j] == Ztile[j]) {484 counter[ j] = 0;490 for (axis = 1; axis < matrix->Naxes; axis++) { 491 counter[axis] ++; 492 if (counter[axis] == Ztile[axis]) { 493 counter[axis] = 0; 485 494 } else { 486 495 break; 487 496 } 488 497 } 489 if ( j== matrix->Naxes) assert (i == Nline - 1); // we should be done here...498 if (axis == matrix->Naxes) assert (i == Nline - 1); // we should be done here... 490 499 491 500 // Naxes = 3 … … 495 504 // determine the offset of the next line relative to the start position 496 505 offset = counter[matrix->Naxes - 1]; 497 for ( j = matrix->Naxes - 2; j >= 0; j--) {498 offset = offset*matrix->Naxis[ j] + counter[j];506 for (axis = matrix->Naxes - 2; axis >= 0; axis--) { 507 offset = offset*matrix->Naxis[axis] + counter[axis]; 499 508 } 500 509 } … … 506 515 507 516 // bitpix is the input data size/type 508 int gfits_distribute_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) { 509 510 int i, j, k; 511 int *counter = NULL; 512 int *Ztile = NULL; 513 514 ALLOCATE (counter, int, matrix->Naxes); 515 ALLOCATE (Ztile, int, matrix->Naxes); 517 int gfits_distribute_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) { 518 OHANA_UNUSED_PARAM(oblank); 519 OHANA_UNUSED_PARAM(zblank); 520 OHANA_UNUSED_PARAM(zzero); 521 OHANA_UNUSED_PARAM(zscale); 522 523 int axis; 524 unsigned int *counter = NULL; 525 unsigned long int *Ztile = NULL; 526 527 ALLOCATE (counter, unsigned int, matrix->Naxes); 528 ALLOCATE (Ztile, unsigned long int, matrix->Naxes); 516 529 517 530 // counter for current row in tile to copy 518 531 // true sizes of this tile (in pixels) 519 for ( i = 0; i < matrix->Naxes; i++) {520 counter[ i] = 0;521 Ztile[ i] = MIN ((matrix->Naxis[i] - otile[i]*ztile[i]), ztile[i]);532 for (axis = 0; axis < matrix->Naxes; axis++) { 533 counter[axis] = 0; 534 Ztile[axis] = MIN ((matrix->Naxis[axis] - otile[axis]*ztile[axis]), ztile[axis]); 522 535 } 523 536 524 537 // number of lines in the tile (in pixels) 525 int Nline = 1;526 int Npix = matrix->Naxis[0];527 for ( i = 1; i < matrix->Naxes; i++) {528 Nline *= Ztile[ i];529 Npix *= matrix->Naxis[ i];538 unsigned long int Nline = 1; 539 unsigned long int Npix = matrix->Naxis[0]; 540 for (axis = 1; axis < matrix->Naxes; axis++) { 541 Nline *= Ztile[axis]; 542 Npix *= matrix->Naxis[axis]; 530 543 } 531 544 … … 536 549 // start = otile[0]*ztile[0] + otile[1]*ztile[1]*Naxis[0] + otile[2]*ztile[2]*Naxis[0]*Naxis[1] + ...; 537 550 // start = otile[0]*ztile[0] + Naxis[0]*(otile[1]*ztile[1] + Naxis[1]*(otile[2]*ztile[2] + ...)); 538 int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1];539 for ( i = matrix->Naxes - 2; i >= 0; i--) {540 int coord = otile[i]*ztile[i];541 start = start*matrix->Naxis[ i] + coord;551 unsigned long int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1]; 552 for (axis = matrix->Naxes - 2; axis >= 0; axis--) { 553 unsigned long int coord = otile[axis]*ztile[axis]; 554 start = start*matrix->Naxis[axis] + coord; 542 555 } 543 556 … … 553 566 554 567 // pixel offset in output array relative to tile start 555 int offset = 0;568 unsigned long int offset = 0; 556 569 557 570 static int pass = 0; 571 int k; 558 572 for (k = 0; k < size; k++) { 573 unsigned long int i; 559 574 for (i = 0; i < Nline; i++) { 560 575 # ifdef BYTE_SWAP … … 564 579 # endif 565 580 char *rawptr = &raw[i*Ztile[0] + k*Nraw]; 581 unsigned long j; 566 582 for (j = 0; j < Ztile[0]; j++, srcptr += size, rawptr ++) { 567 583 if (FALSE && (i == 0) && (j < 4) && (pass == 0)) { … … 574 590 575 591 // update the counters, carrying to the next dimension if needed 576 for ( j = 1; j < matrix->Naxes; j++) {577 counter[ j] ++;578 if (counter[ j] == Ztile[j]) {579 counter[ j] = 0;592 for (axis = 1; axis < matrix->Naxes; axis++) { 593 counter[axis] ++; 594 if (counter[axis] == Ztile[axis]) { 595 counter[axis] = 0; 580 596 } else { 581 597 break; 582 598 } 583 599 } 584 if ( j== matrix->Naxes) assert (i == Nline - 1); // we should be done here...600 if (axis == matrix->Naxes) assert (i == Nline - 1); // we should be done here... 585 601 586 602 // Naxes = 3 … … 590 606 // determine the offset of the next line relative to the start position 591 607 offset = counter[matrix->Naxes - 1]; 592 for ( j = matrix->Naxes - 2; j >= 0; j--) {593 offset = offset*matrix->Naxis[ j] + counter[j];608 for (axis = matrix->Naxes - 2; axis >= 0; axis--) { 609 offset = offset*matrix->Naxis[axis] + counter[axis]; 594 610 } 595 611 } -
trunk/Ohana/src/libfits/matrix/F_uncompress_data.c
r38441 r39457 2 2 # include <gfitsio.h> 3 3 # include <zlib.h> 4 5 /* functions defined in ricecomp.c */ 6 int fits_rcomp(int a[], int nx, unsigned char *c, int clen, int nblock); 7 int fits_rdecomp (unsigned char *c, int clen, unsigned int array[], int nx, int nblock); 8 int fits_rdecomp_short (unsigned char *c, int clen, unsigned short array[], int nx, int nblock); 9 int fits_rdecomp_byte (unsigned char *c, int clen, unsigned char array[], int nx, int nblock); 10 11 /* functions defined in fits_hcompress.c */ 12 # define LONGLONG long long 13 int fits_hcompress(int *a, int ny, int nx, int scale, char *output, long *nbytes, int *status); 14 int fits_hcompress64(LONGLONG *a, int ny, int nx, int scale, char *output, long *nbytes, int *status); 15 16 /* functions defined in fits_hdeccompress.c */ 17 int fits_hdecompress(unsigned char *input, int smooth, int *a, int *ny, int *nx, int *scale, int *status); 18 int fits_hdecompress64(unsigned char *input, int smooth, LONGLONG *a, int *ny, int *nx, int *scale, int *status); 19 20 /* functions defined in pliocomp.c */ 21 int pl_p2li (int *pxsrc, int xs, short *lldst, int npix); 22 int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix); 23 24 /* functions defined in gzip.c */ 25 int gfits_gz_stripheader (unsigned char *data, int *ndata); 26 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 4 # include <gfits_compress.h> 27 5 28 6 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 29 7 30 int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout,int Nout_alloc, int out_pixsize) {8 int gfits_uncompress_data (char *zdata, unsigned long Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, unsigned long int *Nout, unsigned long int Nout_alloc, int out_pixsize) { 31 9 32 10 int status; … … 78 56 79 57 int status = FALSE; 80 int Npix = *Nout / out_pixsize; 81 int k; 58 unsigned long int Npix = *Nout / out_pixsize; 82 59 83 60 switch (out_pixsize) { … … 88 65 case 2: 89 66 if (0) { 90 fprintf (stderr, "Nout: %d, Nrawpix: %d\n", Nzdata, Npix); 67 unsigned long int k; 68 fprintf (stderr, "Nout: %lu, Nrawpix: %lu\n", Nzdata, Npix); 91 69 fprintf (stderr, "cmp out: "); 92 70 for (k = 0; k < Nzdata; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); } … … 112 90 113 91 if (!strcasecmp(cmptype, "PLIO_1")) { 92 int Ntru = *Nout; 114 93 int Npix; 115 Npix = pl_l2pi ((short *) zdata, 1, (int *) outdata, *Nout);116 if (Npix != *Nout) {94 Npix = pl_l2pi ((short *) zdata, 1, (int *) outdata, Ntru); 95 if (Npix != Ntru) { 117 96 fprintf (stderr, "error in plio decompression\n"); 118 97 return (FALSE); … … 122 101 123 102 if (!strcasecmp(cmptype, "HCOMPRESS_1")) { 103 unsigned long int Ntru = *Nout; 124 104 int Nx, Ny, scale; 125 105 status = 0; … … 132 112 // fprintf (stderr, "decompression yields image %d x %d (scale: %d)\n", Nx, Ny, scale); 133 113 134 if (Nx * Ny != *Nout) { 114 unsigned long Npix = Nx * Ny; 115 if (Npix != Ntru) { 135 116 fprintf (stderr, "error in hdecompress: mismatched output size\n"); 136 117 return (FALSE); -
trunk/Ohana/src/libfits/table/F_compress_T.c
r39358 r39457 23 23 # define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; } 24 24 25 int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start,int Nrows);26 int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start,int Nrows);25 int gfits_collect_table_data (FTable *table, TableField *field, char *raw, unsigned long int row_start, unsigned long int Nrows); 26 int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, unsigned long int row_start, unsigned long int Nrows); 27 27 28 28 static float timeSum1 = 0.0; … … 51 51 } 52 52 53 int gfits_compress_table (FTable *srctable, FTable *tgttable, int ztilelen, char *zcmptype) { 54 55 int i, j; 53 int gfits_compress_table (FTable *srctable, FTable *tgttable, unsigned long int ztilelen, char *zcmptype) { 56 54 57 55 char keyword[81]; … … 69 67 gettimeofday (&startTimer, (void *) NULL); 70 68 71 int Ntile, ztilelast;69 unsigned long int Ntile, ztilelast; 72 70 if (!ztilelen) ztilelen = srcheader->Naxis[1]; 73 71 … … 104 102 105 103 ALLOCATE_ZERO (fields, TableField, Nfields); 106 for (i = 0; i < Nfields; i++) { 107 snprintf (keyword, 80, "TTYPE%d", i+1); 108 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE; 109 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE; 104 105 for (int field = 0; field < Nfields; field++) { 106 snprintf (keyword, 80, "TTYPE%d", field+1); 107 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[field].ttype)) ESCAPE; 108 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[field].ttype_cmt)) ESCAPE; 110 109 111 110 // TUNIT is not mandatory 112 snprintf (keyword, 80, "TUNIT%d", i+1);113 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[ i].tunit)) {114 fields[ i].tunit[0] = 0;111 snprintf (keyword, 80, "TUNIT%d", field+1); 112 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[field].tunit)) { 113 fields[field].tunit[0] = 0; 115 114 } else { 116 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[ i].tunit_cmt)) ESCAPE;115 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[field].tunit_cmt)) ESCAPE; 117 116 } 118 117 119 snprintf (keyword, 80, "TFORM%d", i+1);120 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[ i].tformat)) ESCAPE;121 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[ i].tformat_cmt)) ESCAPE;118 snprintf (keyword, 80, "TFORM%d", field+1); 119 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[field].tformat)) ESCAPE; 120 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[field].tformat_cmt)) ESCAPE; 122 121 123 122 // 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 124 strcpy (fields[ i].zctype, zcmptype);123 strcpy (fields[field].zctype, zcmptype); 125 124 126 125 // by using "P" format, we are limited to 32bit pointers (2GB heap) 127 if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[ i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE;126 if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[field].ttype, fields[field].ttype_cmt, fields[field].tunit, 1.0, 0.0)) ESCAPE; 128 127 } 129 128 … … 137 136 char *tmpbuffer = NULL; 138 137 ALLOCATE_ZERO (tmpbuffer, char, 16*Ntile); // need space for Ntile entries, each of width 16 bytes (2 long) 139 for (i = 0; i < Nfields; i++) {140 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[ i].ttype, tmpbuffer, Ntile)) ESCAPE;138 for (int field = 0; field < Nfields; field++) { 139 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[field].ttype, tmpbuffer, Ntile)) ESCAPE; 141 140 } 142 141 free (tmpbuffer); … … 146 145 147 146 // define compression-specific keywords, update header as needed. 148 if (!gfits_modify (tgtheader, "ZTILELEN", "% d", 1, ztilelen)) ESCAPE;147 if (!gfits_modify (tgtheader, "ZTILELEN", "%lu", 1, ztilelen)) ESCAPE; 149 148 150 149 if (!gfits_modify (tgtheader, "ZNAXIS1", OFF_T_FMT, 1, srcheader->Naxis[0])) ESCAPE; … … 163 162 int offset = 0; // bytes from first column of first field to the current field (accumulate to set) 164 163 165 for (i = 0; i < Nfields; i++) {166 snprintf (keyword, 81, "ZFORM%d", i+1);167 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[ i].tformat)) ESCAPE;168 if (!gfits_varlength_column_define (tgttable, &fields[ i].zdef, i+1)) ESCAPE;169 if (!gfits_bintable_format (fields[ i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE; //170 fields[ i].rowsize = fields[i].Nvalues*fields[i].pixsize;171 max_width = MAX(max_width, fields[ i].rowsize);172 173 if (!strcasecmp (fields[ i].zctype, "AUTO")) {174 if (!strcmp (fields[ i].datatype, "short") ||175 !strcmp (fields[ i].datatype, "float") ||176 !strcmp (fields[ i].datatype, "double")||177 !strcmp (fields[ i].datatype, "int64_t")) {178 strcpy (fields[ i].zctype, "GZIP_2");164 for (int field = 0; field < Nfields; field++) { 165 snprintf (keyword, 81, "ZFORM%d", field+1); 166 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[field].tformat)) ESCAPE; 167 if (!gfits_varlength_column_define (tgttable, &fields[field].zdef, field+1)) ESCAPE; 168 if (!gfits_bintable_format (fields[field].tformat, fields[field].datatype, &fields[field].Nvalues, &fields[field].pixsize)) ESCAPE; // 169 fields[field].rowsize = fields[field].Nvalues*fields[field].pixsize; 170 max_width = MAX(max_width, fields[field].rowsize); 171 172 if (!strcasecmp (fields[field].zctype, "AUTO")) { 173 if (!strcmp (fields[field].datatype, "short") || 174 !strcmp (fields[field].datatype, "float") || 175 !strcmp (fields[field].datatype, "double")|| 176 !strcmp (fields[field].datatype, "int64_t")) { 177 strcpy (fields[field].zctype, "GZIP_2"); 179 178 goto got_cmptype; 180 179 } 181 if (!strcmp (fields[ i].datatype, "int")) {182 strcpy (fields[ i].zctype, "RICE_1");180 if (!strcmp (fields[field].datatype, "int")) { 181 strcpy (fields[field].zctype, "RICE_1"); 183 182 goto got_cmptype; 184 183 } 185 if (!strcmp (fields[ i].datatype, "byte") ||186 !strcmp (fields[ i].datatype, "char")) {187 strcpy (fields[ i].zctype, "GZIP_1");184 if (!strcmp (fields[field].datatype, "byte") || 185 !strcmp (fields[field].datatype, "char")) { 186 strcpy (fields[field].zctype, "GZIP_1"); 188 187 goto got_cmptype; 189 188 } … … 193 192 194 193 // OVERRIDE: RICE can only be used on integer fields 195 if (!strcasecmp (fields[ i].zctype, "RICE_1") || !strcasecmp (fields[i].zctype, "RICE_ONE")) {196 if (!strcmp (fields[ i].datatype, "float") || !strcmp (fields[i].datatype, "double") || !strcmp (fields[i].datatype, "int64_t")) {197 strcpy (fields[ i].zctype, "GZIP_2");194 if (!strcasecmp (fields[field].zctype, "RICE_1") || !strcasecmp (fields[field].zctype, "RICE_ONE")) { 195 if (!strcmp (fields[field].datatype, "float") || !strcmp (fields[field].datatype, "double") || !strcmp (fields[field].datatype, "int64_t")) { 196 strcpy (fields[field].zctype, "GZIP_2"); 198 197 } 199 198 } 200 199 201 200 // OVERRIDE: GZIP_2 invalid for B (use GZIP_1) 202 if (!strcasecmp (fields[ i].zctype, "GZIP_2") && !strcmp (fields[i].datatype, "byte")) {203 strcpy (fields[ i].zctype, "GZIP_1");201 if (!strcasecmp (fields[field].zctype, "GZIP_2") && !strcmp (fields[field].datatype, "byte")) { 202 strcpy (fields[field].zctype, "GZIP_1"); 204 203 } 205 204 206 205 // compression type per column (XXX for now we are just using zcmptype, as set above) 207 snprintf (keyword, 81, "ZCTYP%d", i+1);208 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[ i].zctype)) ESCAPE;209 210 fields[ i].offset = offset;211 offset += fields[ i].rowsize;206 snprintf (keyword, 81, "ZCTYP%d", field+1); 207 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[field].zctype)) ESCAPE; 208 209 fields[field].offset = offset; 210 offset += fields[field].rowsize; 212 211 } 213 212 214 213 // allocate the intermediate storage buffers 215 int Nzdata_alloc = 2*max_width*ztilelen + 100;214 unsigned long int Nzdata_alloc = 2*max_width*ztilelen + 100; 216 215 ALLOCATE (raw, char, max_width*ztilelen); 217 216 ALLOCATE (zdata, char, Nzdata_alloc); … … 229 228 // compress the data : copy into a tile, compress the tile, then add to the output table 230 229 // each tile -> 1 row of the output table 231 for ( i = 0; i < Ntile; i++) {232 233 for ( j = 0; j < Nfields; j++) {234 235 gettimeofday (&startTimer, (void *) NULL); 236 237 int Nrows = (i== Ntile - 1) ? ztilelast : ztilelen;238 int row_start = i*ztilelen;230 for (unsigned long int tile = 0; tile < Ntile; tile++) { 231 232 for (int field = 0; field < Nfields; field++) { 233 234 gettimeofday (&startTimer, (void *) NULL); 235 236 unsigned long int Nrows = (tile == Ntile - 1) ? ztilelast : ztilelen; 237 unsigned long int row_start = tile*ztilelen; 239 238 // ^- first row for this tile & field 240 239 // NOTE: assumes each tile has the same length, ex the last (true for now) 241 240 242 241 // copy the raw pixels from their native matrix locations to the temporary output buffer 243 if (!strcasecmp(fields[ j].zctype, "GZIP_2") || !strcasecmp(fields[j].zctype, "NONE_2")) {244 if (!gfits_collect_table_gzp2 (srctable, &fields[ j], raw, row_start, Nrows)) ESCAPE;242 if (!strcasecmp(fields[field].zctype, "GZIP_2") || !strcasecmp(fields[field].zctype, "NONE_2")) { 243 if (!gfits_collect_table_gzp2 (srctable, &fields[field], raw, row_start, Nrows)) ESCAPE; 245 244 } else { 246 if (!gfits_collect_table_data (srctable, &fields[ j], raw, row_start, Nrows)) ESCAPE;245 if (!gfits_collect_table_data (srctable, &fields[field], raw, row_start, Nrows)) ESCAPE; 247 246 } 248 247 … … 256 255 257 256 if (VERBOSE_DUMP) { 258 int k;259 257 fprintf (stderr, "c1: "); 260 for ( k = 0; k < Nrows*fields[j].Nvalues*fields[j].pixsize; k++) {258 for (unsigned long int k = 0; k < Nrows*fields[field].Nvalues*fields[field].pixsize; k++) { 261 259 fprintf (stderr, "%02hhx", raw[k]); 262 260 if (k % 2) fprintf (stderr, " "); … … 269 267 // optname, optvalue = NULL, Noptions = 0 270 268 271 int Nraw = Nrows*fields[j].Nvalues; // number of pixels272 if (!strcasecmp(fields[ j].zctype, "GZIP_1")) {273 if (!gfits_byteswap_zdata (raw, Nraw * fields[ j].pixsize, fields[j].pixsize)) ESCAPE;269 unsigned long int Nraw = Nrows*fields[field].Nvalues; // number of pixels 270 if (!strcasecmp(fields[field].zctype, "GZIP_1")) { 271 if (!gfits_byteswap_zdata (raw, Nraw * fields[field].pixsize, fields[field].pixsize)) ESCAPE; 274 272 } 275 273 … … 281 279 282 280 if (VERBOSE_DUMP) { 283 int k;284 281 fprintf (stderr, "c2: "); 285 for ( k = 0; k < Nrows*fields[j].Nvalues*fields[j].pixsize; k++) {282 for (unsigned long int k = 0; k < Nrows*fields[field].Nvalues*fields[field].pixsize; k++) { 286 283 fprintf (stderr, "%02hhx", raw[k]); 287 284 if (k % 2) fprintf (stderr, " "); … … 291 288 } 292 289 293 int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression294 if (!gfits_compress_data (zdata, &Nzdata, fields[ j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE;290 unsigned long int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression 291 if (!gfits_compress_data (zdata, &Nzdata, fields[field].zctype, NULL, NULL, 0, raw, Nraw, fields[field].pixsize, 0, 0)) ESCAPE; 295 292 296 293 // XXX TIMER 2c … … 301 298 302 299 if (VERBOSE_DUMP) { 303 int k;304 300 fprintf (stderr, "c3: "); 305 for ( k = 0; k < Nzdata; k++) {301 for (unsigned long int k = 0; k < Nzdata; k++) { 306 302 fprintf (stderr, "%02hhx", zdata[k]); 307 303 if (k % 2) fprintf (stderr, " "); … … 311 307 } 312 308 313 if (strcasecmp(fields[ j].zctype, "NONE_2") && // NONE and NONE_1 not swapped?314 strcasecmp(fields[ j].zctype, "GZIP_1") &&315 strcasecmp(fields[ j].zctype, "GZIP_2") &&316 strcasecmp(fields[ j].zctype, "RICE_1") &&317 strcasecmp(fields[ j].zctype, "RICE_ONE")) {318 if (!gfits_byteswap_zdata (zdata, Nzdata, fields[ j].pixsize)) ESCAPE;309 if (strcasecmp(fields[field].zctype, "NONE_2") && // NONE and NONE_1 not swapped? 310 strcasecmp(fields[field].zctype, "GZIP_1") && 311 strcasecmp(fields[field].zctype, "GZIP_2") && 312 strcasecmp(fields[field].zctype, "RICE_1") && 313 strcasecmp(fields[field].zctype, "RICE_ONE")) { 314 if (!gfits_byteswap_zdata (zdata, Nzdata, fields[field].pixsize)) ESCAPE; 319 315 } 320 316 … … 326 322 327 323 if (VERBOSE_DUMP) { 328 int k;329 324 fprintf (stderr, "c4: "); 330 for ( k = 0; k < Nzdata; k++) {325 for (unsigned long int k = 0; k < Nzdata; k++) { 331 326 fprintf (stderr, "%02hhx", zdata[k]); 332 327 if (k % 2) fprintf (stderr, " "); … … 336 331 } 337 332 338 if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, i, &fields[j].zdef)) ESCAPE;333 if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, tile, &fields[field].zdef)) ESCAPE; 339 334 // XXX TIMER 2e 340 335 gettimeofday (&stopTimer, (void *) NULL); … … 347 342 if (OHANA_MEMCHECK) ohana_memcheck (TRUE); 348 343 349 for (i = 0; i < Nfields; i++) {350 if (!gfits_varlength_column_finish (tgttable, &fields[ i].zdef)) ESCAPE;344 for (int field = 0; field < Nfields; field++) { 345 if (!gfits_varlength_column_finish (tgttable, &fields[field].zdef)) ESCAPE; 351 346 } 352 347 … … 375 370 // raw_pixsize is the bytes / pixel for the input matrix 376 371 // place the raw image bytes for the current tile into the tile buffer 377 int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 378 379 off_t i; 372 int gfits_collect_table_data (FTable *table, TableField *field, char *raw, unsigned long int row_start, unsigned long int Nrows) { 380 373 381 374 // we are copying NN rows into the column which starts at XX and has MM bytes per row … … 388 381 389 382 if (VERBOSE) fprintf (stderr, "distribute: "); 390 for ( i = 0; i < Nrows; i++, tblbuffer += Nx) {383 for (unsigned long i = 0; i < Nrows; i++, tblbuffer += Nx) { 391 384 memcpy (&raw[i*rowsize], tblbuffer, rowsize); 392 385 # if (VERBOSE) 393 int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]);386 for (int j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]); 394 387 # endif 395 388 } … … 399 392 } 400 393 401 int gfits_collect_table_data_alt (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 402 403 off_t i; 394 int gfits_collect_table_data_alt (FTable *table, TableField *field, char *raw, unsigned long int row_start, unsigned long int Nrows) { 404 395 405 396 // we are copying NN rows of the column which starts at XX and has MM bytes per row … … 408 399 409 400 if (VERBOSE) fprintf (stderr, "collect: "); 410 for ( i = 0; i < Nrows; i++) {401 for (unsigned long i = 0; i < Nrows; i++) { 411 402 int row = row_start + i; 412 403 memcpy (&raw[i*field->rowsize], &table->buffer[Nx*row + field->offset], field->rowsize); … … 420 411 } 421 412 422 int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 423 424 off_t i, j, k; 413 int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, unsigned long int row_start, unsigned long int Nrows) { 425 414 426 415 // we are copying NN rows into the column which starts at XX and has MM bytes per row … … 433 422 char *rawptr = raw; 434 423 435 for ( k = 0; k < field->pixsize; k++) {424 for (off_t k = 0; k < field->pixsize; k++) { 436 425 # ifdef BYTE_SWAP 437 426 char *tblptr_start = &table->buffer[Nx*row_start + offset + (pixsize - k - 1)]; … … 439 428 char *tblptr_start = &table->buffer[Nx*row_start + offset + k]; 440 429 # endif 441 for ( i = 0; i < Nrows; i++, tblptr_start += Nx) {430 for (unsigned long int i = 0; i < Nrows; i++, tblptr_start += Nx) { 442 431 char *tblptr = tblptr_start; 443 for ( j = 0; j < Nvalues; j++, tblptr += pixsize, rawptr++) {432 for (off_t j = 0; j < Nvalues; j++, tblptr += pixsize, rawptr++) { 444 433 *rawptr = *tblptr; 445 434 } … … 449 438 } 450 439 451 int gfits_collect_table_gzp2_alt (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 452 453 off_t i, j, k; 440 int gfits_collect_table_gzp2_alt (FTable *table, TableField *field, char *raw, unsigned long int row_start, unsigned long int Nrows) { 454 441 455 442 // we are copying NN rows into the column which starts at XX and has MM bytes per row … … 457 444 off_t Nx = table->header->Naxis[0]; 458 445 459 for ( k = 0; k < field->pixsize; k++) {460 for ( i = 0; i < Nrows; i++) {461 int row = row_start + i;446 for (off_t k = 0; k < field->pixsize; k++) { 447 for (unsigned long int i = 0; i < Nrows; i++) { 448 unsigned long int row = row_start + i; 462 449 char *rawptr = &raw[i*field->Nvalues + k*Nrows*field->Nvalues]; 463 450 # ifdef BYTE_SWAP … … 466 453 char *tblptr = &table->buffer[Nx*row + field->offset + k]; 467 454 # endif 468 for ( j = 0; j < field->Nvalues; j++, tblptr += field->pixsize, rawptr++) {455 for (off_t j = 0; j < field->Nvalues; j++, tblptr += field->pixsize, rawptr++) { 469 456 *rawptr = *tblptr; 470 myAssert (rawptr - raw < Nrows*field->Nvalues*field->pixsize, "oops"); 457 myAssert (rawptr >= raw, "oops"); 458 myAssert ((unsigned long int)(rawptr - raw) < Nrows*field->Nvalues*field->pixsize, "oops"); 471 459 myAssert (tblptr - table->buffer < table->header->Naxis[0]*table->header->Naxis[1], "oops"); 472 460 } -
trunk/Ohana/src/libfits/table/F_set_column.c
r39394 r39457 109 109 if (CHECK_MEMBLOCKS) { 110 110 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 111 fprintf (stderr, "ref: "OFF_T_FMT", array: "OFF_T_FMT"\n", (off_t) ref, (off_t) array);111 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %ld, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 112 112 if (!ref->nextBlock && !ref->prevBlock) abort(); 113 113 } … … 120 120 if (CHECK_MEMBLOCKS) { 121 121 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 122 fprintf (stderr, "ref: "OFF_T_FMT", array: "OFF_T_FMT"\n", (off_t) ref, (off_t) array);122 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %ld, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 123 123 if (!ref->nextBlock && !ref->prevBlock) abort(); 124 124 } … … 212 212 if (CHECK_MEMBLOCKS) { 213 213 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 214 fprintf (stderr, "ref: "OFF_T_FMT", array: "OFF_T_FMT"\n", (off_t) ref, (off_t) array);214 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %ld, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 215 215 if (!ref->nextBlock && !ref->prevBlock) abort(); 216 216 } … … 241 241 if (CHECK_MEMBLOCKS) { 242 242 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 243 fprintf (stderr, "ref: "OFF_T_FMT", array: "OFF_T_FMT"\n", (off_t) ref, (off_t) array);243 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %ld, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 244 244 if (!ref->nextBlock && !ref->prevBlock) abort(); 245 245 } -
trunk/Ohana/src/libfits/table/F_table_varlength.c
r39340 r39457 187 187 ptr[0] = Ndata; 188 188 ptr[1] = heap_offset - table->heap_start; 189 // fprintf (stderr, "row: %d, Ndata: %d, maxlen: %d, Ndata: %d, ptr1: %d\n", (int) row, (int) Ndata, (int) column->maxlen, (int) Ndata, (int) (heap_offset - table->heap_start)); 189 190 } 190 191 -
trunk/Ohana/src/libfits/table/F_uncompress_T.c
r39358 r39457 13 13 int gfits_dump_raw_table (FTable *table, char *message) { 14 14 # if (VERBOSE_DUMP) 15 int i;16 15 fprintf (stderr, "%s data:\n", message); 17 for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {16 for (int i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) { 18 17 // for (i = 0; i < 16; i++) { 19 18 fprintf (stderr, "%02hhx", table->buffer[i]); … … 22 21 } 23 22 fprintf (stderr, "\n"); 23 # else 24 OHANA_UNUSED_PARAM(table); 25 OHANA_UNUSED_PARAM(message); 24 26 # endif 25 27 return TRUE; … … 28 30 int gfits_dump_cmp_table (FTable *table, char *message) { 29 31 # if (VERBOSE_DUMP) 30 int i;31 32 fprintf (stderr, "%s pntr:\n", message); 32 for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {33 for (int i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) { 33 34 fprintf (stderr, "%02hhx", table->buffer[i]); 34 35 if (i % 2) fprintf (stderr, " "); … … 38 39 39 40 fprintf (stderr, "%s data:\n", message); 40 for (i = 0; i < table->header->pcount; i++) {41 for (int i = 0; i < table->header->pcount; i++) { 41 42 fprintf (stderr, "%02hhx", table->buffer[table->heap_start + i]); 42 43 if (i % 2) fprintf (stderr, " "); … … 44 45 } 45 46 fprintf (stderr, "\n"); 47 # else 48 OHANA_UNUSED_PARAM(table); 49 OHANA_UNUSED_PARAM(message); 46 50 # endif 47 51 return TRUE; … … 77 81 int gfits_uncompress_table (FTable *srctable, FTable *tgttable) { 78 82 79 int i;80 81 83 char keyword[256]; 82 84 … … 114 116 115 117 ALLOCATE (fields, TableField, Nfields); 116 for (i = 0; i < Nfields; i++) {118 for (int i = 0; i < Nfields; i++) { 117 119 snprintf (keyword, 80, "TTYPE%d", i+1); 118 120 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE; … … 170 172 // calling with an empty data array, data values are not actually copied (this is done 171 173 // below after decompression) 172 for (i = 0; i < Nfields; i++) {174 for (int i = 0; i < Nfields; i++) { 173 175 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, NULL, Ny)) ESCAPE; 174 176 } … … 200 202 gettimeofday (&startTimer, (void *) NULL); 201 203 202 off_t row; 203 for (row = 0; row < srcheader->Naxis[1]; row++) { 204 205 for (i = 0; i < Nfields; i++) { 204 for (off_t row = 0; row < srcheader->Naxis[1]; row++) { 205 206 for (int i = 0; i < Nfields; i++) { 206 207 207 208 // gfits_uncompress_data can take values specific to the compression mode … … 218 219 219 220 if (VERBOSE_DUMP) { 220 int k;221 221 fprintf (stderr, "u4: "); 222 for ( k = 0; k < Nzdata; k++) {222 for (int k = 0; k < Nzdata; k++) { 223 223 fprintf (stderr, "%02hhx", zdata[k]); 224 224 if (k % 2) fprintf (stderr, " "); … … 250 250 251 251 if (VERBOSE_DUMP) { 252 int k;253 252 fprintf (stderr, "u3: "); 254 for ( k = 0; k < Nzdata; k++) {253 for (int k = 0; k < Nzdata; k++) { 255 254 fprintf (stderr, "%02hhx", zdata[k]); 256 255 if (k % 2) fprintf (stderr, " "); … … 266 265 gettimeofday (&startTimer, (void *) NULL); 267 266 268 int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen;269 int Nraw = Nrows*fields[i].Nvalues*fields[i].pixsize; // expected number of bytes267 unsigned long int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen; 268 unsigned long int Nraw = Nrows*fields[i].Nvalues*fields[i].pixsize; // expected number of bytes 270 269 if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, Nraw_alloc, fields[i].pixsize)) ESCAPE; 271 270 272 271 if (VERBOSE_DUMP) { 273 int k;274 272 fprintf (stderr, "u2: "); 275 for ( k = 0; k < Nraw*fields[i].pixsize; k++) {273 for (unsigned long int k = 0; k < Nraw*fields[i].pixsize; k++) { 276 274 fprintf (stderr, "%02hhx", raw[k]); 277 275 if (k % 2) fprintf (stderr, " "); … … 299 297 300 298 if (VERBOSE_DUMP) { 301 int k;302 299 fprintf (stderr, "u1: "); 303 for ( k = 0; k < Nraw*fields[i].pixsize; k++) {300 for (unsigned long int k = 0; k < Nraw*fields[i].pixsize; k++) { 304 301 fprintf (stderr, "%02hhx", raw[k]); 305 302 if (k % 2) fprintf (stderr, " "); … … 356 353 int gfits_distribute_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 357 354 358 off_t i;359 360 355 // we are copying NN rows into the column which starts at XX and has MM bytes per row 361 356 … … 367 362 368 363 if (VERBOSE) fprintf (stderr, "distribute: "); 369 for ( i = 0; i < Nrows; i++, tblbuffer += Nx) {364 for (off_t i = 0; i < Nrows; i++, tblbuffer += Nx) { 370 365 memcpy (tblbuffer, &raw[i*rowsize], rowsize); 371 366 # if (VERBOSE) 372 int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]);367 for (int j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]); 373 368 # endif 374 369 } … … 379 374 380 375 int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 381 382 off_t i, j, k;383 376 384 377 // we are copying NN rows into the column which starts at XX and has MM bytes per row … … 391 384 char *rawptr = raw; 392 385 393 for ( k = 0; k < field->pixsize; k++) {386 for (off_t k = 0; k < field->pixsize; k++) { 394 387 # ifdef BYTE_SWAP 395 388 char *tblptr_start = &table->buffer[Nx*row_start + offset + (pixsize - k - 1)]; … … 397 390 char *tblptr_start = &table->buffer[Nx*row_start + offset + k]; 398 391 # endif 399 for ( i = 0; i < Nrows; i++, tblptr_start += Nx) {392 for (off_t i = 0; i < Nrows; i++, tblptr_start += Nx) { 400 393 char *tblptr = tblptr_start; 401 for ( j = 0; j < Nvalues; j++, tblptr += pixsize, rawptr++) {394 for (off_t j = 0; j < Nvalues; j++, tblptr += pixsize, rawptr++) { 402 395 *tblptr = *rawptr; 403 396 } … … 409 402 int gfits_distribute_table_gzp2_alt (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 410 403 411 off_t i, j, k;412 413 404 // we are copying NN rows into the column which starts at XX and has MM bytes per row 414 405 415 406 off_t Nx = table->header->Naxis[0]; 416 407 417 for ( k = 0; k < field->pixsize; k++) {418 for ( i = 0; i < Nrows; i++) {408 for (off_t k = 0; k < field->pixsize; k++) { 409 for (off_t i = 0; i < Nrows; i++) { 419 410 int row = row_start + i; 420 411 char *rawptr = &raw[i*field->Nvalues + k*Nrows*field->Nvalues]; … … 424 415 char *tblptr = &table->buffer[Nx*row + field->offset + k]; 425 416 # endif 426 for ( j = 0; j < field->Nvalues; j++, tblptr += field->pixsize, rawptr++) {417 for (off_t j = 0; j < field->Nvalues; j++, tblptr += field->pixsize, rawptr++) { 427 418 *tblptr = *rawptr; 428 419 } -
trunk/Ohana/src/libfits/table/F_write_T.c
r38553 r39457 27 27 myAssert (myBlock->startblock == OHANA_MEMMAGIC, "bad memory"); 28 28 myAssert (myBlock->endblock == OHANA_MEMMAGIC, "bad memory"); 29 myAssert (myBlock->size >= table[0].datasize, "overflow");29 myAssert (myBlock->size >= (size_t) table[0].datasize, "overflow"); 30 30 } 31 31 # endif -
trunk/Ohana/src/libfits/table/F_write_TH.c
r38553 r39457 27 27 myAssert (myBlock->startblock == OHANA_MEMMAGIC, "bad memory"); 28 28 myAssert (myBlock->endblock == OHANA_MEMMAGIC, "bad memory"); 29 myAssert (myBlock->size >= header[0].datasize, "overflow");29 myAssert (myBlock->size >= (size_t) header[0].datasize, "overflow"); 30 30 } 31 31 # endif -
trunk/Ohana/src/libfits/test/imagecomp.c
r38553 r39457 17 17 static int NY = 10; 18 18 19 int main ( int argc, char **argv) {19 int main (void) { 20 20 21 21 plan_tests (3*3*234); … … 196 196 } 197 197 198 int Ztile[2] = {NX, NY};199 ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, ( int *) &Ztile, zcmptype), "compressed image");198 unsigned long int Ztile[2] = {NX, NY}; 199 ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, (unsigned long int *) &Ztile, zcmptype), "compressed image"); 200 200 // ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, NULL, zcmptype), "compressed image"); 201 201 ok (gfits_uncompress_image (&outheader, &outmatrix, &ftable), "uncompressed image"); -
trunk/Ohana/src/libfits/test/keywords.c
r39321 r39457 15 15 tmp = Pout[3]; Pout[3] = Pout[4]; Pout[4] = tmp; } 16 16 17 int main ( int argc, char **argv) {17 int main (void) { 18 18 19 19 plan_tests (14); … … 21 21 diag ("libfits keyword tests"); 22 22 23 int i, err;24 double srcbuf[NSRC], tgtbuf[NTGT], outbuf[NOUT];25 26 23 { 27 24 … … 96 93 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 97 94 98 ok (gfits_modify (&header, "D_LONG3", "%Ld", 1, (long long) 0x100), "wrote a keyword"); 99 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 95 // this is not ISO C99: 96 // ok (gfits_modify (&header, "D_LONG3", "%Ld", 1, (long long) 0x100), "wrote a keyword"); 97 // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 100 98 101 99 // set one of each of the few numerical types (unsigned ints) … … 109 107 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 110 108 111 ok (gfits_modify (&header, "DU_LONG3", "%Lu", 1, (long long) 0x100), "wrote a keyword");112 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");109 // ok (gfits_modify (&header, "DU_LONG3", "%Lu", 1, (long long) 0x100), "wrote a keyword"); 110 // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 113 111 114 112 ok (gfits_modify (&header, "D_SHORT", "%hd", 1, 0x20), "wrote a keyword"); … … 229 227 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 230 228 231 ok (gfits_scan (&header, "D_LONG3", "%Ld", 1, &Kvalue), "read a keyword");232 ok (Kvalue == 0x100, "got the right value");233 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");229 // ok (gfits_scan (&header, "D_LONG3", "%Ld", 1, &Kvalue), "read a keyword"); 230 // ok (Kvalue == 0x100, "got the right value"); 231 // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 234 232 235 233 // set one of each of the few numerical types (unsigned ints) … … 246 244 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 247 245 248 ok (gfits_scan (&header, "DU_LONG3", "%Lu", 1, &Ulonglong), "read a keyword");249 ok (Ulonglong == 0x100, "got the right value");250 ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");246 // ok (gfits_scan (&header, "DU_LONG3", "%Lu", 1, &Ulonglong), "read a keyword"); 247 // ok (Ulonglong == 0x100, "got the right value"); 248 // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good"); 251 249 252 250 ok (gfits_scan (&header, "D_SHORT", "%hd", 1, &Ishort), "read a keyword"); -
trunk/Ohana/src/libfits/test/ricetest.c
r38404 r39457 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 # include <gfits_compress.h> 3 4 # include "tap_ohana.h" 4 5 … … 6 7 # define NBYTE 4*NPIX 7 8 8 int main ( int argc, char **argv) {9 int main (void) { 9 10 10 11 plan_tests (45); … … 12 13 diag ("libfits ricetest.c tests"); 13 14 14 // buffers to store max array15 char rawdata[NBYTE];16 char cmpdata[NBYTE];17 char outdata[NBYTE];18 19 15 // ok (1, "failure"); 20 16 21 17 if (1) { 18 // buffers to store max array 19 char rawdata[NBYTE]; 20 unsigned char outdata[NBYTE]; 21 unsigned char cmpdata[NBYTE]; 22 22 char *rawvalue = (char *) rawdata; 23 23 char *outvalue = (char *) outdata; … … 46 46 47 47 if (1) { 48 // buffers to store max array 49 char rawdata[NBYTE]; 50 unsigned short outdata[NBYTE]; 51 unsigned char cmpdata[NBYTE]; 52 48 53 short *rawvalue = (short *) rawdata; 49 54 short *outvalue = (short *) outdata; … … 72 77 73 78 if (1) { 79 // buffers to store max array 80 char rawdata[NBYTE]; 81 unsigned int outdata[NBYTE]; 82 unsigned char cmpdata[NBYTE]; 83 74 84 int *rawvalue = (int *) rawdata; 75 85 int *outvalue = (int *) outdata; -
trunk/Ohana/src/libfits/test/tablecomp.c
r38553 r39457 10 10 char *cmptype[] = {"NONE", "NONE_1", "NONE_2", "GZIP_1", "GZIP_2", "RICE_1", "RICE_ONE", "AUTO", NULL}; 11 11 12 int main ( int argc, char **argv) {13 14 plan_tests (668 );12 int main (void) { 13 14 plan_tests (668+428); 15 15 16 16 diag ("libfits tablecomp.c tests"); … … 28 28 test_compress_empty (cmptype[i]); 29 29 ok (ohana_memcheck (TRUE), "no memory corruption"); 30 ohana_memdump (TRUE); 30 31 } 31 32 … … 89 90 ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table"); 90 91 92 if (0) { int ix, iy; 93 for (ix = 0; ix < 12; ix++) { 94 for (iy = 0; iy < 16; iy++) { 95 fprintf (stderr, "%x ", (int) cmptable.buffer[ix*16 + iy]); 96 } 97 } 98 } 99 100 Header rawheader; 101 FTable rawtable; 102 rawtable.header = &rawheader; 103 ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table"); 104 105 gfits_free_header (&cmpheader); 106 gfits_free_table (&cmptable); 107 108 outheader = &rawheader; 109 outtable = &rawtable; 110 } 111 112 char type[16]; 113 int Ncol; 114 off_t Nrow; 115 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"); 122 123 // count mismatched values 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)"); 150 151 free (VAL_B); 152 free (VAL_I); 153 free (VAL_J); 154 free (VAL_K); 155 free (VAL_E); 156 free (VAL_D); 157 158 free (VAL_B_t); 159 free (VAL_I_t); 160 free (VAL_J_t); 161 free (VAL_K_t); 162 free (VAL_E_t); 163 free (VAL_D_t); 164 165 gfits_free_header (&header); 166 gfits_free_table (&ftable); 167 if (zcmptype) { 168 gfits_free_header (outheader); 169 gfits_free_table (outtable); 170 } 171 return TRUE; 172 } 173 174 int test_compress_fullrange (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 175 176 Header header; 177 FTable ftable; 178 179 diag ("--- starting test_compress with zcmptype %s ---", zcmptype); 180 ok (gfits_init_header (&header), "inited the header"); 181 ok (gfits_init_table (&ftable), "inited the table"); 182 183 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 184 185 ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte", "none", 1.0, 0.0), "defined byte column"); 186 ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short", "none", 1.0, 0.0), "defined short column"); 187 ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int", "none", 1.0, 0.0), "defined int column"); 188 ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long", "none", 1.0, 0.0), "defined long column"); 189 ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float", "degree", 1.0, 0.0), "defined float column"); 190 ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0), "defined double column"); 191 192 // generate the output array that carries the data 193 ok (gfits_create_table (&header, &ftable), "created the basic table"); 194 195 int Nval = 1000; 196 char *VAL_B; ALLOCATE (VAL_B, char, Nval); 197 short *VAL_I; ALLOCATE (VAL_I, short, Nval); 198 int *VAL_J; ALLOCATE (VAL_J, int, Nval); 199 int64_t *VAL_K; ALLOCATE (VAL_K, int64_t, Nval); 200 float *VAL_E; ALLOCATE (VAL_E, float, Nval); 201 double *VAL_D; ALLOCATE (VAL_D, double, Nval); 202 203 long A = time(NULL); 204 srand48(A); 205 206 int i; 207 for (i = 0; i < Nval; i++) { 208 VAL_B[i] = 0xff & lrand48(); 209 VAL_I[i] = 0xffff & lrand48(); 210 VAL_J[i] = 0xffffffff & lrand48(); 211 VAL_K[i] = (((int64_t)lrand48()) << 32) + (int64_t)lrand48(); 212 VAL_E[i] = FLT_MAX * (2.0*drand48() - 1.0); 213 VAL_D[i] = DBL_MAX * (2.0*drand48() - 1.0); 214 } 215 216 // add the columns to the output array 217 ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte table column"); 218 ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short table column"); 219 ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int table column"); 220 ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long table column"); 221 ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float table column"); 222 ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column"); 223 224 Header *outheader = &header; 225 FTable *outtable = &ftable; 226 227 if (zcmptype) { 228 Header cmpheader; 229 FTable cmptable; 230 cmptable.header = &cmpheader; 231 ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table"); 232 91 233 Header rawheader; 92 234 FTable rawtable; … … 120 262 int NVAL_D_bad = 0; 121 263 122 // for (i = 0; i < Nval; i++) {123 // fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);124 // }125 126 264 for (i = 0; i < Nval; i++) { 127 265 if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++; … … 140 278 ok (!NVAL_D_bad, "double values match (input vs output)"); 141 279 280 free (VAL_B); 281 free (VAL_I); 282 free (VAL_J); 283 free (VAL_K); 284 free (VAL_E); 285 free (VAL_D); 286 287 free (VAL_B_t); 288 free (VAL_I_t); 289 free (VAL_J_t); 290 free (VAL_K_t); 291 free (VAL_E_t); 292 free (VAL_D_t); 293 142 294 gfits_free_header (&header); 143 295 gfits_free_table (&ftable); … … 149 301 } 150 302 151 int test_compress_fullrange (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 303 int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 304 305 Header header; 306 FTable ftable; 307 308 diag ("--- starting test_compress with zcmptype %s ---", zcmptype); 309 ok (gfits_init_header (&header), "inited the header"); 310 ok (gfits_init_table (&ftable), "inited the table"); 311 312 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 313 314 ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column"); 315 316 // generate the output array that carries the data 317 ok (gfits_create_table (&header, &ftable), "created the basic table"); 318 319 int Nval = 1000; 320 short *SEQ; ALLOCATE (SEQ, short, Nval); 321 322 int i; 323 for (i = 0; i < Nval; i++) { 324 SEQ[i] = i; 325 } 326 327 // add the columns to the output array 328 ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short table column"); 329 330 Header *outheader = &header; 331 FTable *outtable = &ftable; 332 333 if (zcmptype) { 334 Header cmpheader; 335 FTable cmptable; 336 cmptable.header = &cmpheader; 337 ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table"); 338 339 Header rawheader; 340 FTable rawtable; 341 rawtable.header = &rawheader; 342 ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table"); 343 344 gfits_free_header (&cmpheader); 345 gfits_free_table (&cmptable); 346 347 outheader = &rawheader; 348 outtable = &rawtable; 349 } 350 351 char type[16]; 352 int Ncol; 353 off_t Nrow; 354 355 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"); 356 357 // count mismatched values 358 int Nseq = 0; 359 for (i = 0; i < Nval; i++) { 360 if (SEQ[i] != SEQ_t[i]) Nseq++; 361 } 362 363 ok (!Nseq, "short values match (input vs output)"); 364 365 gfits_free_header (&header); 366 gfits_free_table (&ftable); 367 if (zcmptype) { 368 gfits_free_header (outheader); 369 gfits_free_table (outtable); 370 } 371 return TRUE; 372 } 373 374 int test_compress_empty (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 152 375 153 376 Header header; … … 170 393 ok (gfits_create_table (&header, &ftable), "created the basic table"); 171 394 172 int Nval = 1000;395 int Nval = 0; 173 396 char *VAL_B; ALLOCATE (VAL_B, char, Nval); 174 397 short *VAL_I; ALLOCATE (VAL_I, short, Nval); … … 178 401 double *VAL_D; ALLOCATE (VAL_D, double, Nval); 179 402 180 long A = time(NULL);181 srand48(A);182 183 403 int i; 184 404 for (i = 0; i < Nval; i++) { 185 VAL_B[i] = 0xff & lrand48();186 VAL_I[i] = 0xffff & lrand48();187 VAL_J[i] = 0xffffffff & lrand48();188 VAL_K[i] = (((int64_t)lrand48()) << 32) + (int64_t)lrand48();189 VAL_E[i] = FLT_MAX * (2.0*drand48() - 1.0);190 VAL_D[i] = DBL_MAX * (2.0*drand48() - 1.0);405 VAL_B[i] = (i % 255) - 128; 406 VAL_I[i] = i; 407 VAL_J[i] = 10000*i + 100*i; 408 VAL_K[i] = 10000*i + 330*i; 409 VAL_E[i] = 0.1*i; 410 VAL_D[i] = 1.001*i; 191 411 } 192 412 … … 206 426 FTable cmptable; 207 427 cmptable.header = &cmpheader; 208 ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table");428 ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table"); 209 429 210 430 Header rawheader; … … 239 459 int NVAL_D_bad = 0; 240 460 461 // for (i = 0; i < Nval; i++) { 462 // fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]); 463 // } 464 241 465 for (i = 0; i < Nval; i++) { 242 466 if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++; … … 255 479 ok (!NVAL_D_bad, "double values match (input vs output)"); 256 480 481 free (VAL_B); 482 free (VAL_I); 483 free (VAL_J); 484 free (VAL_K); 485 free (VAL_E); 486 free (VAL_D); 487 488 free (VAL_B_t); 489 free (VAL_I_t); 490 free (VAL_J_t); 491 free (VAL_K_t); 492 free (VAL_E_t); 493 free (VAL_D_t); 494 257 495 gfits_free_header (&header); 258 496 gfits_free_table (&ftable); … … 264 502 } 265 503 266 int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 267 268 Header header; 269 FTable ftable; 270 271 diag ("--- starting test_compress with zcmptype %s ---", zcmptype); 272 ok (gfits_init_header (&header), "inited the header"); 273 ok (gfits_init_table (&ftable), "inited the table"); 274 275 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 276 277 ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column"); 278 279 // generate the output array that carries the data 280 ok (gfits_create_table (&header, &ftable), "created the basic table"); 281 282 int Nval = 1000; 283 short *SEQ; ALLOCATE (SEQ, short, Nval); 284 285 int i; 286 for (i = 0; i < Nval; i++) { 287 SEQ[i] = i; 288 } 289 290 // add the columns to the output array 291 ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short table column"); 292 293 Header *outheader = &header; 294 FTable *outtable = &ftable; 295 296 if (zcmptype) { 297 Header cmpheader; 298 FTable cmptable; 299 cmptable.header = &cmpheader; 300 ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table"); 301 302 Header rawheader; 303 FTable rawtable; 304 rawtable.header = &rawheader; 305 ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table"); 306 307 gfits_free_header (&cmpheader); 308 gfits_free_table (&cmptable); 309 310 outheader = &rawheader; 311 outtable = &rawtable; 312 } 313 314 char type[16]; 315 int Ncol; 316 off_t Nrow; 317 318 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"); 319 320 // count mismatched values 321 int Nseq = 0; 322 for (i = 0; i < Nval; i++) { 323 if (SEQ[i] != SEQ_t[i]) Nseq++; 324 } 325 326 ok (!Nseq, "short values match (input vs output)"); 327 328 gfits_free_header (&header); 329 gfits_free_table (&ftable); 330 if (zcmptype) { 331 gfits_free_header (outheader); 332 gfits_free_table (outtable); 333 } 334 return TRUE; 335 } 336 337 int test_compress_empty (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 338 339 Header header; 340 FTable ftable; 341 342 diag ("--- starting test_compress with zcmptype %s ---", zcmptype); 343 ok (gfits_init_header (&header), "inited the header"); 344 ok (gfits_init_table (&ftable), "inited the table"); 345 346 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 347 348 ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte", "none", 1.0, 0.0), "defined byte column"); 349 ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short", "none", 1.0, 0.0), "defined short column"); 350 ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int", "none", 1.0, 0.0), "defined int column"); 351 ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long", "none", 1.0, 0.0), "defined long column"); 352 ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float", "degree", 1.0, 0.0), "defined float column"); 353 ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0), "defined double column"); 354 355 // generate the output array that carries the data 356 ok (gfits_create_table (&header, &ftable), "created the basic table"); 357 358 int Nval = 0; 359 char *VAL_B; ALLOCATE (VAL_B, char, Nval); 360 short *VAL_I; ALLOCATE (VAL_I, short, Nval); 361 int *VAL_J; ALLOCATE (VAL_J, int, Nval); 362 int64_t *VAL_K; ALLOCATE (VAL_K, int64_t, Nval); 363 float *VAL_E; ALLOCATE (VAL_E, float, Nval); 364 double *VAL_D; ALLOCATE (VAL_D, double, Nval); 365 366 int i; 367 for (i = 0; i < Nval; i++) { 368 VAL_B[i] = (i % 255) - 128; 369 VAL_I[i] = i; 370 VAL_J[i] = 10000*i + 100*i; 371 VAL_K[i] = 10000*i + 330*i; 372 VAL_E[i] = 0.1*i; 373 VAL_D[i] = 1.001*i; 374 } 375 376 // add the columns to the output array 377 ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte table column"); 378 ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short table column"); 379 ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int table column"); 380 ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long table column"); 381 ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float table column"); 382 ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column"); 383 384 Header *outheader = &header; 385 FTable *outtable = &ftable; 386 387 if (zcmptype) { 388 Header cmpheader; 389 FTable cmptable; 390 cmptable.header = &cmpheader; 391 ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table"); 392 393 Header rawheader; 394 FTable rawtable; 395 rawtable.header = &rawheader; 396 ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table"); 397 398 gfits_free_header (&cmpheader); 399 gfits_free_table (&cmptable); 400 401 outheader = &rawheader; 402 outtable = &rawtable; 403 } 404 405 char type[16]; 406 int Ncol; 407 off_t Nrow; 408 409 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"); 410 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"); 411 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"); 412 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"); 413 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"); 414 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"); 415 416 // count mismatched values 417 int NVAL_B_bad = 0; 418 int NVAL_I_bad = 0; 419 int NVAL_J_bad = 0; 420 int NVAL_K_bad = 0; 421 int NVAL_E_bad = 0; 422 int NVAL_D_bad = 0; 423 424 // for (i = 0; i < Nval; i++) { 425 // fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]); 426 // } 427 428 for (i = 0; i < Nval; i++) { 429 if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++; 430 if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++; 431 if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++; 432 if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++; 433 if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++; 434 if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++; 435 } 436 437 ok (!NVAL_B_bad, "byte values match (input vs output)"); 438 ok (!NVAL_I_bad, "short values match (input vs output)"); 439 ok (!NVAL_J_bad, "int values match (input vs output)"); 440 ok (!NVAL_K_bad, "int64_t values match (input vs output)"); 441 ok (!NVAL_E_bad, "float values match (input vs output)"); 442 ok (!NVAL_D_bad, "double values match (input vs output)"); 443 444 gfits_free_header (&header); 445 gfits_free_table (&ftable); 446 if (zcmptype) { 447 gfits_free_header (outheader); 448 gfits_free_table (outtable); 449 } 450 return TRUE; 451 } 452 453 504 -
trunk/Ohana/src/libfits/test/zlib.c
r38442 r39457 16 16 tmp = Pout[3]; Pout[3] = Pout[4]; Pout[4] = tmp; } 17 17 18 int main ( int argc, char **argv) {18 int main (void) { 19 19 20 20 plan_tests (14); … … 30 30 { 31 31 z_stream zdn; 32 zdn.next_in = ( char *) srcbuf;32 zdn.next_in = (unsigned char *) srcbuf; 33 33 zdn.avail_in = NSRC * sizeof(double); 34 zdn.next_out = ( char *) tgtbuf;34 zdn.next_out = (unsigned char *) tgtbuf; 35 35 zdn.avail_out = NTGT * sizeof(double); 36 36 … … 83 83 { 84 84 z_stream zup; 85 zup.next_in = ( char *) tgtbuf;85 zup.next_in = (unsigned char *) tgtbuf; 86 86 zup.avail_in = NTGT * sizeof(double); 87 zup.next_out = ( char *) outbuf;87 zup.next_out = (unsigned char *) outbuf; 88 88 zup.avail_out = NOUT * sizeof(double); 89 89 … … 120 120 { 121 121 z_stream zdn; 122 zdn.next_in = ( char *) srcbuf;122 zdn.next_in = (unsigned char *) srcbuf; 123 123 zdn.avail_in = NSRC * sizeof(double); 124 zdn.next_out = ( char *) tgtbuf;124 zdn.next_out = (unsigned char *) tgtbuf; 125 125 zdn.avail_out = NTGT * sizeof(double); 126 126 … … 174 174 { 175 175 z_stream zup; 176 zup.next_in = ( char *) tgtbuf;176 zup.next_in = (unsigned char *) tgtbuf; 177 177 zup.avail_in = NTGT * sizeof(double); 178 zup.next_out = ( char *) outbuf;178 zup.next_out = (unsigned char *) outbuf; 179 179 zup.avail_out = NOUT * sizeof(double); 180 180
Note:
See TracChangeset
for help on using the changeset viewer.
