IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 2, 2007, 5:01:45 PM (19 years ago)
Author:
Paul Price
Message:

Cleaning up some code, using PS_ASSERT_FITS_NON_NULL instead of custom code in each function. Adding function to determine if the FITS file pointer is on a PHU that should truly be a FITS image (but it's compressed so it's a FITS table, which can't be the PHU). Putting hooks to this function into the header and image read functions, so that they read what the user Really Wants. This behaviour (which some may not want if they want the unadulterated FITS file) can be turned off by setting psFits.compression=false (default is true). This works for reading uncompressed data, data we've compressed ourselves, and data compressed with fpack-0.93. It doesn't yet work with data compressed with cfitsio's imcopy program (due to multiple EXTNAME keywords; about to put in a fix for this).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_070920/psLib/src/fits/psFitsImage.c

    r15110 r15168  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.17.14.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-09-29 21:55:05 $
     9 *  @version $Revision: 1.17.14.2 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-10-03 03:01:45 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5454                                              )
    5555{
    56     PS_ASSERT_PTR_NON_NULL(fits, NULL);
     56    PS_ASSERT_FITS_NON_NULL(fits, NULL);
    5757    PS_ASSERT_INT_NONNEGATIVE(z, NULL);
    5858
     
    219219                        )
    220220{
     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
    221230    p_psFitsReadInfo *info = p_psFitsReadInfoAlloc(fits, region, z);
    222231
     
    241250                              )
    242251{
     252    PS_ASSERT_FITS_NON_NULL(fits, NULL);
     253    PS_ASSERT_INT_NONNEGATIVE(z, NULL);
     254
    243255    if (output && output->parent) {
    244256        psError(PS_ERR_IO, true, "Unable to read into a buffer for a child image.\n");
    245257        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.");
    246264    }
    247265
     
    268286                      const char* extname)
    269287{
     288    PS_ASSERT_FITS_NON_NULL(fits, false);
     289    PS_ASSERT_IMAGE_NON_NULL(input, false);
    270290    // this is equivalent to insert after the last HDU
    271291
     
    281301                       bool after)
    282302{
    283 
    284     if (!fits) {
    285         psError(PS_ERR_BAD_PARAMETER_NULL, true, _("The input psFits object can not NULL."));
    286         return false;
    287     }
    288 
    289     if (!input) {
    290         psError(PS_ERR_BAD_PARAMETER_NULL, true, _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    291         return false;
    292     }
     303    PS_ASSERT_FITS_NON_NULL(fits, false);
     304    PS_ASSERT_IMAGE_NON_NULL(input, false);
    293305
    294306    int numCols = input->numCols;       // Number of columns for image
     
    389401                       int z)
    390402{
     403    PS_ASSERT_FITS_NON_NULL(fits, false);
     404    PS_ASSERT_IMAGE_NON_NULL(input, false);
     405
    391406    int status = 0;
    392 
    393     if (fits == NULL) {
    394         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    395                 _("The input psFits object can not NULL."));
    396         return false;
    397     }
    398 
    399     if (input == NULL) {
    400         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    401                 _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    402         return false;
    403     }
    404407
    405408    // check to see if we are positioned on an image HDU
     
    497500psArray *psFitsReadImageCube(const psFits *fits, psRegion region)
    498501{
     502    PS_ASSERT_FITS_NON_NULL(fits, NULL);
     503
    499504    int nAxis = 0;                      // Number of axes
    500505    long nAxes[3];                      // Number of pixels on each axis
     
    502507    char fitsErr[80] = "";              // CFITSIO error message string
    503508
    504     if (fits == NULL) {
    505         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    506                 _("The input psFits object can not NULL."));
    507         return NULL;
    508     }
    509 
    510509    // Some of this replicates what is in psFitsReadImage, so it's a little inefficient.  But it saves
    511510    // 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    }
    512517
    513518    if (fits_get_img_dim(fits->fd, &nAxis, &status) != 0) {
     
    542547
    543548    // Bad dimensionality
    544     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);
    545552    return NULL;
    546553}
     
    548555bool psFitsWriteImageCube(psFits *fits, psMetadata *header, const psArray *input, const char *extname)
    549556{
    550     if (fits == NULL) {
    551         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    552                 _("The input psFits object can not NULL."));
    553         return false;
    554     }
    555 
    556     if (input == NULL) {
    557         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    558                 _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    559         return false;
    560     }
     557    PS_ASSERT_FITS_NON_NULL(fits, false);
     558    PS_ASSERT_ARRAY_NON_NULL(input, false);
    561559
    562560    if (input->n == 0) {
     
    590588    }
    591589    bool update = psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS", PS_META_REPLACE, "Dimensionality", 3) &&
    592                   psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS1", PS_META_REPLACE, "Number of columns", numCols) &&
    593                   psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS2", PS_META_REPLACE, "Number of rows", numRows) &&
    594                   psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS3", PS_META_REPLACE, "Number of image planes",
    595                                    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);
    596594    if (! update) {
    597595        psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s."),
     
    623621bool psFitsUpdateImageCube(psFits *fits, const psArray *input, int x0, int y0)
    624622{
    625     if (fits == NULL) {
    626         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    627                 _("The input psFits object can not NULL."));
    628         return false;
    629     }
    630 
    631     if (input == NULL) {
    632         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    633                 _("The input psImage was NULL.  Need a non-NULL psImage for operation to be performed."));
    634         return false;
    635     }
     623    PS_ASSERT_FITS_NON_NULL(fits, false);
     624    PS_ASSERT_ARRAY_NON_NULL(input, false);
    636625
    637626    if (input->n == 0) {
Note: See TracChangeset for help on using the changeset viewer.