Changeset 41521 for trunk/psLib/src/fits/psFitsImage.c
- Timestamp:
- Apr 2, 2021, 2:14:14 PM (5 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsImage.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsImage.c
r41504 r41521 292 292 psRandom *rng, // Random number generator 293 293 bool newScaleZero // Determine a new BSCALE and BZERO? 294 )294 ) 295 295 { 296 296 psAssert(bscale, "impossible"); … … 307 307 308 308 psFitsOptions *options = fits->options; // Options for FITS writing 309 310 // psMemCheckCorruption (stderr, true); // 1311 309 312 310 // Can't PLIO compress U16,U32,U64 directly, so convert them … … 331 329 } 332 330 333 // psMemCheckCorruption (stderr, true); // 1x334 335 331 // Custom floating-point 336 332 if (PS_IS_PSELEMTYPE_REAL(image->type.type) && options->conventions.psBitpix && … … 345 341 } 346 342 347 // psMemCheckCorruption (stderr, true); // 2348 349 343 // Quantise floating-point images 350 344 if (PS_IS_PSELEMTYPE_REAL(image->type.type) && options->bitpix > 0) { 351 if (newScaleZero) {345 if (newScaleZero) { 352 346 // Choose an appropriate BSCALE and BZERO 353 347 if (!psFitsScaleDetermine(bscale, bzero, boffset, bsoften, blank, image, mask, maskVal, fits)) { … … 357 351 return psMemIncrRefCounter((psImage*)image); 358 352 } 359 } else {353 } else { 360 354 // Don't want to muck with the current BSCALE and BZERO. Get the current values and use those. 361 355 int status = 0; // Status of cfitsio 362 356 if (fits_read_key_dbl(fits->fd, "BSCALE", bscale, NULL, &status) && status != KEY_NO_EXIST) { 363 psFitsError(status, true, "Unable to read header.");364 return NULL;357 psFitsError(status, true, "Unable to read header."); 358 return NULL; 365 359 } 366 367 // psMemCheckCorruption (stderr, true); // 2x368 360 369 361 status = 0; 370 362 if (fits_read_key_dbl(fits->fd, "BZERO", bzero, NULL, &status) && status != KEY_NO_EXIST) { 371 psFitsError(status, true, "Unable to read header.");372 return NULL;363 psFitsError(status, true, "Unable to read header."); 364 return NULL; 373 365 } 374 366 status = 0; 375 367 if (*bscale == 0.0) { 376 psError(PS_ERR_IO, true,377 "Supposed to use old values of BSCALE and BZERO, but they don't exist.");378 return NULL;368 psError(PS_ERR_IO, true, 369 "Supposed to use old values of BSCALE and BZERO, but they don't exist."); 370 return NULL; 379 371 } 380 381 // psMemCheckCorruption (stderr, true); // 3 382 383 } 384 385 // XXX this test triggers the pswarp memory corruption problem. you need to include "psThread.h" above to activate this 386 // for (int nx = 0; nx < 3; nx++) { 387 // psList *pending = psThreadGetPendingQueue(); 388 // if (pending && pending->head) { 389 // fprintf (stderr, "thread jobs are still pending...\n"); 390 // } 391 // // XXX can we mess up the memory? 392 // psImage *temp1 = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32); 393 // fprintf (stderr, "corruption check set 1\n"); 394 // psMemCheckCorruption (stderr, true); 395 // psImageInit (temp1, 2.0); 396 // psFree (temp1); 397 // fprintf (stderr, "corruption check set 2\n"); 398 // psMemCheckCorruption (stderr, true); 399 // } 400 401 // fprintf (stderr, "corruption check psFitsInsertImageWithMask\n"); 402 // psMemCheckCorruption (stderr, true); 403 372 } 404 373 psImage *out = psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, *bsoften, rng); 405 374 return out; … … 407 376 408 377 // Choose the appropriate output type, given the input type and desired bits per pixel 409 #define CONVERT_TYPE_INT_CASE(OUTTYPE, INTYPE, BITPIX) \410 case BITPIX:\411 OUTTYPE = PS_IS_PSELEMTYPE_UNSIGNED(INTYPE) ? PS_TYPE_U##BITPIX : PS_TYPE_S##BITPIX; \378 #define CONVERT_TYPE_INT_CASE(OUTTYPE, INTYPE, BITPIX) \ 379 case BITPIX: \ 380 OUTTYPE = PS_IS_PSELEMTYPE_UNSIGNED(INTYPE) ? PS_TYPE_U##BITPIX : PS_TYPE_S##BITPIX; \ 412 381 break; 413 #define CONVERT_TYPE_FLOAT_CASE(OUTTYPE, BITPIX) \414 case -BITPIX: /* Note the use of the negative sign */\415 OUTTYPE = PS_TYPE_F##BITPIX;\382 #define CONVERT_TYPE_FLOAT_CASE(OUTTYPE, BITPIX) \ 383 case -BITPIX: /* Note the use of the negative sign */ \ 384 OUTTYPE = PS_TYPE_F##BITPIX; \ 416 385 break; 417 386 418 419 // psMemCheckCorruption (stderr, true); // 4420 387 421 388 *bscale = 1.0; … … 501 468 502 469 // No need to apply the BSCALE, BZERO because cfitsio does this for us 503 470 504 471 return true; 505 472 } … … 668 635 } 669 636 670 // fprintf (stderr, "calling psFitsInsertImageWithMask for %s, %lx, %lx\n", fits->fd->Fptr->filename, (long int) image, (long int) mask);671 672 637 int numCols = image->numCols; // Number of columns for image 673 638 int numRows = image->numRows; // Number of rows for image … … 682 647 psFitsFloat floatType; // Custom floating-point convention type 683 648 684 // psMemCheckCorruption (stderr, true);685 686 649 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, 687 650 fits, image, mask, maskVal, NULL, true); // Image to write out 688 689 // psMemCheckCorruption (stderr, true);690 691 // fprintf (stderr, "allocated in psFitsInsertImageWithMask %s, %lx\n", fits->fd->Fptr->filename, (long int) diskImage);692 651 693 652 if (!diskImage) { … … 726 685 727 686 psFitsOptions *options = fits->options; // FITS I/O options 728 /* if (options) { */729 /* if (options->scaling == PS_FITS_SCALE_LOG_RANGE) { */730 /* fprintf(stderr,"it has the scaling I expect\n"); */731 /* } */732 /* else { */733 /* fprintf(stderr,"it does nto have the scaling I expect\n"); */734 /* } */735 /* } */736 /* else { */737 /* fprintf(stderr,"options is null, apparently? \n"); */738 /* } */739 687 740 688 psAssert(!useRequestedScale || !options || bitPix == options->bitpix || options->bitpix == 0, … … 830 778 831 779 if (isfinite(bzero) && isfinite(bscale) && (bscale != 0.0)) { 832 fits_write_key_dbl(fits->fd, "BZERO", bzero, 12,780 fits_write_key_dbl(fits->fd, "BZERO", bzero, 12, 833 781 "Scaling: TRUE = BZERO + BSCALE * DISK", &status); 834 782 fits_write_key_dbl(fits->fd, "BSCALE", bscale, 12, … … 885 833 if (image->parent == NULL) { 886 834 // if no parent, assume that the image data is contiguous 887 fits_write_img(fits->fd, dataType, 1, numCols*numRows, diskImage->data.V[0], &status);835 fits_write_img(fits->fd, dataType, 1, numCols*numRows, diskImage->data.V[0], &status); 888 836 } else { 889 837 // image data may not be contiguous; write one row at a time
Note:
See TracChangeset
for help on using the changeset viewer.
