IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 3, 2007, 11:27:21 AM (19 years ago)
Author:
Paul Price
Message:

Merging branch with FITS compression development.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFitsImage.c

    r10999 r15179  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-01-09 22:38:52 $
     9 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-10-03 21:27:21 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3838
    3939// Information required to read a FITS file
    40 typedef struct
    41 {
     40typedef struct {
    4241    int nAxis;                          // Number of axes
    4342    int bitPix;                         // Bits per pixel
     
    4847    int fitsDatatype;                   // cfitsio data type
    4948    int psDatatype;                     // psLib data type
    50 }
    51 p_psFitsReadInfo;
     49} p_psFitsReadInfo;
    5250
    5351static p_psFitsReadInfo *p_psFitsReadInfoAlloc(const psFits *fits, // The FITS file handle
     
    5654                                              )
    5755{
    58     PS_ASSERT_PTR_NON_NULL(fits, NULL);
     56    PS_ASSERT_FITS_NON_NULL(fits, NULL);
    5957    PS_ASSERT_INT_NONNEGATIVE(z, NULL);
    6058
     
    221219                        )
    222220{
     221    PS_ASSERT_FITS_NON_NULL(fits, NULL);
     222    PS_ASSERT_INT_NONNEGATIVE(z, NULL);
     223
     224    if (psFitsCheckSingleCompressedImagePHU(fits, NULL)) {
     225        // This is really what we want, not the empty PHU
     226        psTrace("psLib.fits", 1,
     227                "This PHU should really be a compressed image --- reading that image instead.");
     228    }
     229
    223230    p_psFitsReadInfo *info = p_psFitsReadInfoAlloc(fits, region, z);
    224231
     
    243250                              )
    244251{
     252    PS_ASSERT_FITS_NON_NULL(fits, NULL);
     253    PS_ASSERT_INT_NONNEGATIVE(z, NULL);
     254
    245255    if (output && output->parent) {
    246256        psError(PS_ERR_IO, true, "Unable to read into a buffer for a child image.\n");
    247257        return NULL;
     258    }
     259
     260    if (psFitsCheckSingleCompressedImagePHU(fits, NULL)) {
     261        // This is really what we want, not the empty PHU
     262        psTrace("psLib.fits", 1,
     263                "This PHU should really be a compressed image --- reading that image instead.");
    248264    }
    249265
     
    270286                      const char* extname)
    271287{
     288    PS_ASSERT_FITS_NON_NULL(fits, false);
     289    PS_ASSERT_IMAGE_NON_NULL(input, false);
    272290    // this is equivalent to insert after the last HDU
    273291
     
    283301                       bool after)
    284302{
    285 
    286     if (!fits) {
    287         psError(PS_ERR_BAD_PARAMETER_NULL, true, _("The input psFits object can not NULL."));
    288         return false;
    289     }
    290 
    291     if (!input) {
    292         psError(PS_ERR_BAD_PARAMETER_NULL, true, _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    293         return false;
    294     }
     303    PS_ASSERT_FITS_NON_NULL(fits, false);
     304    PS_ASSERT_IMAGE_NON_NULL(input, false);
    295305
    296306    int numCols = input->numCols;       // Number of columns for image
     
    391401                       int z)
    392402{
     403    PS_ASSERT_FITS_NON_NULL(fits, false);
     404    PS_ASSERT_IMAGE_NON_NULL(input, false);
     405
    393406    int status = 0;
    394 
    395     if (fits == NULL) {
    396         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    397                 _("The input psFits object can not NULL."));
    398         return false;
    399     }
    400 
    401     if (input == NULL) {
    402         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    403                 _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    404         return false;
    405     }
    406407
    407408    // check to see if we are positioned on an image HDU
     
    499500psArray *psFitsReadImageCube(const psFits *fits, psRegion region)
    500501{
     502    PS_ASSERT_FITS_NON_NULL(fits, NULL);
     503
    501504    int nAxis = 0;                      // Number of axes
    502505    long nAxes[3];                      // Number of pixels on each axis
     
    504507    char fitsErr[80] = "";              // CFITSIO error message string
    505508
    506     if (fits == NULL) {
    507         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    508                 _("The input psFits object can not NULL."));
    509         return NULL;
    510     }
    511 
    512509    // Some of this replicates what is in psFitsReadImage, so it's a little inefficient.  But it saves
    513510    // code replication, and should be sufficient for our needs.
     511
     512    if (psFitsCheckSingleCompressedImagePHU(fits, NULL)) {
     513        // This is really what we want, not the empty PHU
     514        psTrace("psLib.fits", 1,
     515                "This PHU should really be a compressed image --- reading that image instead.");
     516    }
    514517
    515518    if (fits_get_img_dim(fits->fd, &nAxis, &status) != 0) {
     
    544547
    545548    // Bad dimensionality
    546     psError(PS_ERR_IO, true, _("Image number of dimensions, %d, is not valid.  Only two or three dimensions supported for FITS I/O."), nAxis);
     549    psError(PS_ERR_IO, true,
     550            _("Image number of dimensions, %d, is not valid."
     551              " Only two or three dimensions supported for FITS I/O."), nAxis);
    547552    return NULL;
    548553}
     
    550555bool psFitsWriteImageCube(psFits *fits, psMetadata *header, const psArray *input, const char *extname)
    551556{
    552     if (fits == NULL) {
    553         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    554                 _("The input psFits object can not NULL."));
    555         return false;
    556     }
    557 
    558     if (input == NULL) {
    559         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    560                 _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    561         return false;
    562     }
     557    PS_ASSERT_FITS_NON_NULL(fits, false);
     558    PS_ASSERT_ARRAY_NON_NULL(input, false);
    563559
    564560    if (input->n == 0) {
     
    592588    }
    593589    bool update = psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS", PS_META_REPLACE, "Dimensionality", 3) &&
    594                   psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS1", PS_META_REPLACE, "Number of columns", numCols) &&
    595                   psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS2", PS_META_REPLACE, "Number of rows", numRows) &&
    596                   psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS3", PS_META_REPLACE, "Number of image planes",
    597                                    input->n);
     590        psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS1", PS_META_REPLACE, "Number of columns", numCols) &&
     591        psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS2", PS_META_REPLACE, "Number of rows", numRows) &&
     592        psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS3", PS_META_REPLACE, "Number of image planes",
     593                         input->n);
    598594    if (! update) {
    599595        psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s."),
     
    625621bool psFitsUpdateImageCube(psFits *fits, const psArray *input, int x0, int y0)
    626622{
    627     if (fits == NULL) {
    628         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    629                 _("The input psFits object can not NULL."));
    630         return false;
    631     }
    632 
    633     if (input == NULL) {
    634         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    635                 _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    636         return false;
    637     }
     623    PS_ASSERT_FITS_NON_NULL(fits, false);
     624    PS_ASSERT_ARRAY_NON_NULL(input, false);
    638625
    639626    if (input->n == 0) {
Note: See TracChangeset for help on using the changeset viewer.