IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 27, 2004, 11:55:09 AM (22 years ago)
Author:
gusciora
Message:

Added function parameter checking for psStats.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psStats.c

    r2217 r2220  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-27 21:06:30 $
     11 *  @version $Revision: 1.75 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-27 21:55:09 $
    1313n *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    14371437psHistogram* psHistogramAlloc(float lower, float upper, psS32 n)
    14381438{
     1439    PS_INT_CHECK_POSITIVE(n, NULL);
     1440    PS_FLOAT_COMPARE(lower, upper, NULL);
     1441
    14391442    psS32 i = 0;                  // Loop index variable
    14401443    psHistogram* newHist = NULL;        // The new histogram structure
    14411444    float binSize = 0.0;        // The histogram bin size
    14421445
    1443     // NOTE: Verify that this is the correct action.
    1444     if (n == 0) {
    1445         return (NULL);
    1446     }
    1447     if (n < 0) {
    1448         psAbort(__func__, "psHistogramAlloc() called with bin size %d.\n", n);
    1449     }
    1450     // NOTE: Verify that this is the correct action.
    1451     if (lower > upper) {
    1452         return (NULL);
    1453     }
    14541446    // Allocate memory for the new histogram structure.  If there are N
    14551447    // bins, then there are N+1 bounds to those bins.
     
    14941486psHistogram* psHistogramAllocGeneric(const psVector* restrict bounds)
    14951487{
     1488    PS_VECTOR_CHECK_NULL(bounds, NULL);
     1489    PS_VECTOR_CHECK_TYPE(bounds, PS_TYPE_F32, NULL);
     1490    PS_INT_COMPARE(bounds->n, 2, NULL);
     1491
    14961492    psHistogram* newHist = NULL;        // The new histogram structure
    14971493    psS32 i;                      // Loop index variable
    14981494
    1499     // NOTE: Verify that this is the correct action.
    1500     if (bounds == NULL) {
    1501         // psAbort(__func__, "psHistogram requested with NULL bounds");
    1502         return (NULL);
    1503     }
    1504     // NOTE: Verify that this is the correct action.
    1505     if (bounds->n <= 1) {
    1506         // psAbort(__func__, "psHistogram requested with NULL bounds");
    1507         return (NULL);
    1508     }
    1509 
    1510     if (bounds->type.type != PS_TYPE_F32) {
    1511         // psAbort(__func__, "psHistogram request a bound which is not type F32");
    1512         return (NULL);
    1513     }
    15141495    // Allocate memory for the new histogram structure.
    15151496    newHist = (psHistogram* ) psAlloc(sizeof(psHistogram));
     
    15621543                               psU32 maskVal)
    15631544{
     1545    PS_PTR_CHECK_NULL(out, NULL);
     1546    PS_VECTOR_CHECK_TYPE(out->bounds, PS_TYPE_F32, NULL);
     1547    PS_VECTOR_CHECK_TYPE(out->nums, PS_TYPE_U32, NULL);
     1548    PS_VECTOR_CHECK_NULL(in, NULL);
     1549    if (mask != NULL) {
     1550        PS_VECTOR_CHECK_SIZE_EQUAL(in, mask, NULL);
     1551        PS_VECTOR_CHECK_TYPE(mask, PS_TYPE_U8, NULL);
     1552    }
     1553
    15641554    psS32 i = 0;                  // Loop index variable
    15651555    float binSize = 0.0;        // Histogram bin size
     
    15711561    psVector* inF32;
    15721562    psS32 mustFreeTmp = 1;
    1573 
    1574     // NOTE: Verify that this is the correct action.
    1575     if (out == NULL) {
    1576         return (NULL);
    1577     }
    1578     // Check the specified output histogram for type psF32
    1579     if (out->bounds->type.type != PS_TYPE_F32) {
    1580         psAbort(__func__, "Only data type PS_TYPE_F32 for the output.bounds member.");
    1581     }
    1582 
    1583     if (out->nums->type.type != PS_TYPE_U32) {
    1584         psAbort(__func__, "Only data type PS_TYPE_U32 for out->nums member.");
    1585     }
    1586     // NOTE: Verify that this is the correct action.
    1587     if (in == NULL) {
    1588         return (out);
    1589     }
    1590 
    1591     if (mask != NULL) {
    1592         if (in->n != mask->n) {
    1593             psError(__func__, "Vector data and vector mask are of different sizes.");
    1594         }
    1595         if (mask->type.type != PS_TYPE_U8) {
    1596             psError(__func__, "Vector mask must be type PS_TYPE_U8");
    1597         }
    1598     }
    1599 
    16001563    inF32 = p_psConvertToF32((psVector *) in);
    16011564    if (inF32 == NULL) {
     
    17211684                       psU32 maskVal)
    17221685{
     1686    PS_PTR_CHECK_NULL(stats, NULL);
     1687    PS_VECTOR_CHECK_NULL(in, NULL);
     1688    if (mask != NULL) {
     1689        PS_VECTOR_CHECK_SIZE_EQUAL(mask, in, NULL);
     1690        PS_VECTOR_CHECK_TYPE(mask, PS_TYPE_U8, NULL);
     1691    }
    17231692    psVector* inF32;
    17241693    psS32 mustFreeTmp = 1;
    1725 
    1726     if (in == NULL) {
    1727         psError(__func__, "in is NULL\n");
    1728         return(stats);
    1729     }
    1730     PS_PTR_CHECK_NULL(stats, NULL);
    17311694
    17321695    inF32 = p_psConvertToF32((psVector *) in);
     
    17351698        mustFreeTmp = 0;
    17361699    }
     1700
    17371701    if ((stats->options & PS_STAT_USE_RANGE) && (stats->min >= stats->max)) {
    1738         psError(__func__, "psVectorStats() called with range: %f to %f\n", stats->min, stats->max);
    1739         return(stats);
    1740     }
    1741 
    1742     if (mask != NULL) {
    1743         PS_VECTOR_CHECK_SIZE_EQUAL(mask, in, NULL);
    1744         PS_VECTOR_CHECK_TYPE(mask, PS_TYPE_U8, NULL);
    1745     }
     1702        PS_FLOAT_COMPARE(stats->max, stats->min, stats);
     1703    }
     1704
    17461705    // ************************************************************************
    17471706    if (stats->options & PS_STAT_SAMPLE_MEAN) {
Note: See TracChangeset for help on using the changeset viewer.