IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 30, 2004, 12:22:00 PM (22 years ago)
Author:
gusciora
Message:

Added better error checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/pmSubtractSky.c

    r2848 r2857  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-12-29 22:44:33 $
     8 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-12-30 22:22:00 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    106106                }
    107107            }
    108             myStats = psVectorStats(myStats, binVector, NULL, binMask, 1);
     108            psStats *rc1 = psVectorStats(myStats, binVector, NULL, binMask, 1);
     109            if (rc1 == NULL) {
     110                psError(PS_ERR_UNKNOWN, false, "psVectorStats(): could not perform requested statistical operation.  Returning in image.\n");
     111                return(origImage);
     112            }
    109113            psF64 statValue;
    110             psBool rc = p_psGetStatValue(myStats, &statValue);
     114            psBool rc = p_psGetStatValue(rc1, &statValue);
    111115
    112116            if (rc == true) {
     
    427431            (fit != PM_FIT_POLYNOMIAL) &&
    428432            (fit != PM_FIT_SPLINE)) {
    429         psError(PS_ERR_UNKNOWN, true, "psFit is unallowable (%d)\n", fit);
     433        psError(PS_ERR_UNKNOWN, true, "psFit is unallowable (%d).  Returning in image.\n", fit);
    430434        return(in);
    431435    }
     
    436440    if ((fitSpec == NULL) ||
    437441            ((fit == PM_FIT_NONE) || (fit == PM_FIT_SPLINE))) {
     442        psLogMsg(__func__, PS_LOG_WARN, "Fit specs are poorly defined.  Returning in image.\n");
    438443        return(in);
    439444    }
     
    452457            psLogMsg(__func__, PS_LOG_WARN, "WARNING: Multiple statistical options have been requested.\n");
    453458            statOptions = getHighestPriorityStatOption(statOptions);
    454 
     459            if (statOptions == -1) {
     460                psError(PS_ERR_UNKNOWN, true, "Not allowable stats->option was specified.  Returning in image.\n");
     461                return(in);
     462            }
    455463            // Save old input "stats" parameter.
    456464            oldStatOptions = stats->options;
     
    483491        // and a mask.
    484492        binnedImage = psImageCopy(binnedImage, origImage, PS_TYPE_F32);
     493        if (binnedImage == NULL) {
     494            psError(PS_ERR_UNKNOWN, false, "psImageCopy() returned NULL.  Returning in image.\n");
     495            return(in);
     496        }
     497
    485498        if (in->mask != NULL) {
    486499            binnedMaskImage = psImageCopy(binnedMaskImage, in->mask, PS_TYPE_U8);
     500            if (binnedMaskImage == NULL) {
     501                psError(PS_ERR_UNKNOWN, false, "psImageCopy() returned NULL.  Returning in image.\n");
     502                psFree(binnedImage);
     503                return(in);
     504            }
    487505        } else {
    488506            binnedMaskImage = psImageAlloc(binnedImage->numCols,
     
    493511    } else {
    494512        binnedImage = psImageRebin(NULL, origImage, in->mask, 0, binFactor, stats);
     513        if (binnedImage == NULL) {
     514            psError(PS_ERR_UNKNOWN, false, "psImageRebin() returned NULL.  Returning in image.\n");
     515            return(in);
     516        }
    495517        binnedMaskImage = psImageAlloc(binnedImage->numCols,
    496518                                       binnedImage->numRows,
     
    512534        psF64 binnedStdev;
    513535        psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    514         myStats =  psImageStats(myStats, binnedImage, NULL, 0);
    515         p_psGetStatValue(myStats, &binnedMean);
     536        psStats *rc =  psImageStats(myStats, binnedImage, NULL, 0);
     537        if (rc == NULL) {
     538            psError(PS_ERR_UNKNOWN, false, "psImageStats(): could not perform requested statistical operation.  Returning in image.\n");
     539            return(in);
     540        }
     541        if (false == p_psGetStatValue(rc, &binnedMean)) {
     542            psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine requested statistical operation.  Returning in image.\n");
     543            return(in);
     544        }
    516545        psTrace(".psModule.pmSubtractSky", 6,
    517546                "binned Mean is %f\n", binnedMean);
    518547
    519548        myStats->options = PS_STAT_SAMPLE_STDEV;
    520         myStats =  psImageStats(myStats, binnedImage, NULL, 0);
    521         p_psGetStatValue(myStats, &binnedStdev);
     549        rc =  psImageStats(myStats, binnedImage, NULL, 0);
     550        if (rc == NULL) {
     551            psError(PS_ERR_UNKNOWN, false, "psImageStats(): could not perform requested statistical operation.  Returning in image.\n");
     552            return(in);
     553        }
     554        if (false == p_psGetStatValue(myStats, &binnedStdev)) {
     555            psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine requested statistical operation.  Returning in image.\n");
     556            return(in);
     557        }
    522558        psFree(myStats);
    523559        psTrace(".psModule.pmSubtractSky", 6,
     
    551587            // Set the pixels in the binned image to that of the polynomial.
    552588            binnedImage = psImageEvalPolynomial(binnedImage, myPoly);
     589            if (binnedImage == NULL) {
     590                psError(PS_ERR_UNKNOWN, false, "psImageEvalPolynomial() returned NULL.  Returning in image.\n");
     591                psFree(binnedMaskImage);
     592                if (!((binFactor <= 1) || (stats == NULL))) {
     593                    psFree(binnedImage);
     594                }
     595                if (oldStatOptions != 0) {
     596                    stats->options = statOptions;
     597                }
     598                return(in);
     599            }
    553600        } else {
    554601            psLogMsg(__func__, PS_LOG_WARN,
     
    565612    } else {
    566613        // We shouldn't get here since we check this above.
    567         psError(PS_ERR_UNKNOWN, true, "Unallowable fit type.");
     614        psError(PS_ERR_UNKNOWN, true, "Unallowable fit type.  Returning in image.\n");
     615        psFree(binnedMaskImage);
     616        if (!((binFactor <= 1) || (stats == NULL))) {
     617            psFree(binnedImage);
     618        }
     619        if (oldStatOptions != 0) {
     620            stats->options = statOptions;
     621        }
     622        return(in);
    568623    }
    569624
Note: See TracChangeset for help on using the changeset viewer.