Changeset 18156
- Timestamp:
- Jun 16, 2008, 4:46:05 PM (18 years ago)
- Location:
- trunk/psLib/src/fits
- Files:
-
- 2 edited
-
psFitsImage.c (modified) (16 diffs)
-
psFitsScale.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsImage.c
r17660 r18156 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $10 * @date $Date: 2008-0 5-14 01:27:25 $9 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-06-17 02:46:05 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 287 287 if (!psFitsScaleDetermine(bscale, bzero, blank, image, fits)) { 288 288 // We can't have the write dying for this reason --- try to save it somehow! 289 psWarning("Unable to determine BSCALE and BZERO for image --- setting to 1.0, 0.0");289 psWarning("Unable to determine BSCALE and BZERO for image --- refusing to quantise."); 290 290 psErrorClear(); 291 return psMemIncrRefCounter((psImage*)image); 291 292 } 292 293 } else { … … 521 522 int numRows = image->numRows; // Number of rows for image 522 523 int status = 0; // Status from cfitsio 523 524 double bscale = 0.0, bzero = 0.0; // Scale and zero point to put in header (*already* applied to data) 524 psFitsCompression *compress = NULL; // FITS compression parameters; to save state 525 526 double bscale = NAN, bzero = NAN; // Scale and zero point to put in header 525 527 long blank = 0; // Blank (undefined) value for image 526 528 psFitsFloat floatType; // Custom floating-point convention type … … 529 531 if (!diskImage) { 530 532 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); 531 return false; 533 goto INSERT_FAIL; 534 } 535 536 if (!isfinite(bscale) || !isfinite(bzero)) { 537 // Couldn't scale, so don't compress. Save compression parameters for later 538 compress = psFitsCompressionGet(fits); 539 if (!psFitsSetCompression(fits, PS_FITS_COMPRESS_NONE, NULL, 0, 0, 0)) { 540 psError(PS_ERR_IO, false, "Unable to unset compression."); 541 goto INSERT_FAIL; 542 } 532 543 } 533 544 … … 537 548 int dataType; // cfitsio data type 538 549 if (!p_psFitsTypeToCfitsio(diskImage->type.type, &bitPix, &cfitsioBzero, &dataType)) { 539 psFree(diskImage); 540 return false; 550 goto INSERT_FAIL; 541 551 } 542 552 if (cfitsioBzero != 0.0) { … … 578 588 fits_insert_img(fits->fd, bitPix, naxis, naxes, &status); 579 589 } 590 if (psFitsError(status, true, "Could not create image HDU.")) { 591 goto INSERT_FAIL; 592 } 580 593 581 594 // write the header, if any. 582 595 if (header && !psFitsWriteHeader(fits, header)) { 583 596 psError(PS_ERR_IO, false, "Unable to write FITS header.\n"); 584 psFree(diskImage); 585 return false; 597 goto INSERT_FAIL; 586 598 } 587 599 … … 597 609 "Scaling: TRUE = BZERO + BSCALE * DISK", &status); 598 610 if (psFitsError(status, true, "Could not write BSCALE/BZERO headers to file.")) { 599 psFree(diskImage); 600 return false; 611 goto INSERT_FAIL; 601 612 } 602 613 } … … 610 621 fits_set_imgnull(fits->fd, blank, &status); 611 622 if (psFitsError(status, true, "Could not write BLANK header to file.")) { 612 psFree(diskImage); 613 return false; 623 goto INSERT_FAIL; 614 624 } 615 625 } … … 634 644 } 635 645 } 636 646 if (psFitsError(status, true, "Could not write image to file.")) { 647 goto INSERT_FAIL; 648 } 649 650 return true; 651 652 INSERT_FAIL: 637 653 psFree(diskImage); 638 639 if (psFitsError(status, true, "Could not write image to file.")) { 640 return false; 641 } 642 643 return true; 644 654 if (compress) { 655 // Restore compression state 656 psFitsCompressionApply(fits, compress); 657 psFree(compress); 658 } 659 return false; 645 660 } 646 661 … … 666 681 int numCols = input->numCols; 667 682 int numRows = input->numRows; 668 669 double bscale = 0.0, bzero = 0.0; // Scale and zero point to put in header (*already* applied to data) 683 psFitsCompression *compress = NULL; // FITS compression parameters; to save state 684 685 double bscale = NAN, bzero = NAN; // Scale and zero point to put in header 670 686 long blank = 0; // Blank (undefined) value for image 671 687 psFitsFloat floatType; // Custom floating-point convention type … … 674 690 if (!diskImage) { 675 691 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); 676 return false; 692 goto UPDATE_FAIL; 693 } 694 695 if (!isfinite(bscale) || !isfinite(bzero)) { 696 // Couldn't scale, so don't compress. Save compression parameters for later 697 compress = psFitsCompressionGet(fits); 698 if (!psFitsSetCompression(fits, PS_FITS_COMPRESS_NONE, NULL, 0, 0, 0)) { 699 psError(PS_ERR_IO, false, "Unable to unset compression."); 700 goto UPDATE_FAIL; 701 } 677 702 } 678 703 … … 682 707 int dataType; // cfitsio data type 683 708 if (!p_psFitsTypeToCfitsio(diskImage->type.type, &bitPix, &cfitsioBzero, &dataType)) { 684 psFree(diskImage); 685 return false; 709 goto UPDATE_FAIL; 686 710 } 687 711 if (cfitsioBzero != 0.0) { … … 694 718 psAssert(!options || bitPix == options->bitpix || options->bitpix == 0, "impossible"); 695 719 696 // check to see if the HDU has the same datatype720 // Check to see if the HDU has the same datatype 697 721 int fileBitpix; 698 722 int naxis; … … 705 729 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 706 730 _("Current FITS HDU has %ld z-planes, but z-plane %d was specified."), nAxes[2], z); 707 psFree(diskImage); 708 return false; 731 goto UPDATE_FAIL; 709 732 } 710 733 … … 728 751 "Input image [size of %ix%i] at position (%i,%i) does not all lay in the %lix%li FITS image.", 729 752 numCols, numRows, x0, y0, nAxes[0], nAxes[1]); 730 psFree(diskImage); 731 return false; 753 goto UPDATE_FAIL; 732 754 } 733 755 … … 736 758 // appropriate scale and zero (because we want to apply a randomiser to the quantisation). 737 759 fits_set_bscale(fits->fd, 1.0, cfitsioBzero, &status); 738 739 760 fits_write_subset(fits->fd, dataType, firstPixel, lastPixel, diskImage->data.V[0], &status); 740 761 if (psFitsError(status, true, "Could not write data to file.")) { 762 goto UPDATE_FAIL; 763 } 764 765 return true; 766 767 UPDATE_FAIL: 741 768 psFree(diskImage); 742 743 if (psFitsError(status, true, "Could not write data to file.")) {744 return false;745 }746 747 return true;769 if (compress) { 770 // Restore compression state 771 psFitsCompressionApply(fits, compress); 772 psFree(compress); 773 } 774 return false; 748 775 } 749 776 -
trunk/psLib/src/fits/psFitsScale.c
r17660 r18156 176 176 PS_ASSERT_FITS_NON_NULL(fits, false); 177 177 178 *bscale = 1.0;179 *bzero = 0.0;178 *bscale = NAN; 179 *bzero = NAN; 180 180 *blank = 0; 181 181
Note:
See TracChangeset
for help on using the changeset viewer.
