IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2218


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

Added parameter checking for psFunctions.c.

Location:
trunk/psLib/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/psConstants.h

    r2217 r2218  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-10-27 21:06:30 $
     8 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-10-27 21:25:52 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636}
    3737
     38#define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \
     39if ((NAME1 - NAME2) < -FLT_EPSILON) { \
     40    psError(__func__,"%s is less than %s.", #NAME1, #NAME2); \
     41    return(RVAL); \
     42}
     43
    3844
    3945
     
    5460}
    5561
     62#define PS_PTR_CHECK_SIZE_EQUAL(PTR1, PTR2, RVAL) \
     63if (PTR1->n != PTR2->n) { \
     64    psError(__func__,"ptr %s has size %d, ptr %s has size %d.", #PTR1, PTR1->n, #PTR2, PTR2->n); \
     65    return(RVAL); \
     66}
     67
     68#define PS_PTR_CHECK_TYPE_EQUAL(PTR1, PTR2, RVAL) \
     69if (PTR1->type.type != PTR2->type.type) { \
     70    psError(__func__,"ptr %s has type %d, ptr %s has type %d.", #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \
     71    return(RVAL); \
     72}
    5673
    5774
  • trunk/psLib/src/dataManip/psFunctions.c

    r2217 r2218  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-27 21:06:30 $
     9 *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-27 21:25:52 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    16881688                            float max)
    16891689{
     1690    PS_INT_CHECK_NON_NEGATIVE(numSplines, NULL);
     1691    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     1692    PS_FLOAT_COMPARE(max, min, NULL);
     1693
    16901694    psSpline1D *tmp = NULL;
    16911695    psS32 i;
    16921696    float tmpDomain;
    16931697    float width;
    1694 
    1695     if (fabs(max-min) < FLT_EPSILON) {
    1696         psLogMsg(__func__, PS_LOG_WARN, "min and max are the same.\n");
    1697         return(NULL);
    1698     }
    16991698
    17001699    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
     
    17531752                                   psS32 order)
    17541753{
     1754    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     1755    PS_VECTOR_CHECK_NULL(bounds, NULL);
     1756    PS_VECTOR_CHECK_EMPTY(bounds, NULL);
     1757
    17551758    psSpline1D *tmp = NULL;
    17561759    psS32 i;
     
    18981901                          psScalar *x)
    18991902{
    1900     if (x->type.type != bins->type.type) {
    1901         psError(__func__, "x->type.type != bins->type.type");
    1902         return(-2);
    1903     }
     1903    PS_PTR_CHECK_TYPE_EQUAL(x, bins, -2);
    19041904
    19051905    if (x->type.type == PS_TYPE_S32) {
     
    19271927                               float x)
    19281928{
     1929    PS_INT_CHECK_NON_NEGATIVE(n, NAN);
     1930    PS_PTR_CHECK_NULL(domain, NAN);
     1931    PS_PTR_CHECK_NULL(range, NAN);
     1932
    19291933    psS32 i;
    19301934    psS32 m;
     
    20372041                                psScalar *x)
    20382042{
     2043    PS_VECTOR_CHECK_NULL(domain, NULL);
     2044    PS_VECTOR_CHECK_NULL(range, NULL);
     2045    PS_PTR_CHECK_NULL(x, NULL);
     2046    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     2047    PS_VECTOR_CHECK_SIZE_EQUAL(domain, range, NULL);
     2048    PS_PTR_CHECK_TYPE_EQUAL(domain, range, NULL);
     2049    PS_PTR_CHECK_TYPE_EQUAL(domain, x, NULL);
     2050
    20392051    psVector *range32 = NULL;
    20402052    psVector *domain32 = NULL;
     
    20422054            "---- p_psVectorInterpolate() begin ----\n");
    20432055
    2044     if ((domain->type.type != range->type.type) ||
    2045             (domain->type.type != x->type.type)) {
    2046         // XXX psError
    2047         printf("p_psVectorInterpolate(): domain->type.type != range->type.type != x->type.type\n");
    2048         printf("%d %d %d\n", domain->type.type, range->type.type, x->type.type);
    2049         exit(1);
    2050     }
    2051     if (domain->n != range->n) {
    2052         // XXX psError
    2053         printf("domain->n != range->n\n");
    2054         exit(1);
    2055     }
    20562056    if (order > (domain->n - 1)) {
    2057         // XXX psError: not enough data points for order-order interpolation.
    2058         printf("not enough data points for order-order interpolation.\n");
    2059         exit(1);
     2057        psError(__func__, "not enough data points for %d-order interpolation.\n", order);
     2058        return(NULL);
    20602059    }
    20612060
     
    20892088    } else {
    20902089        // XXX psError: type not supported
    2091         printf("XXX psError: type not supported\n");
    2092     }
    2093 
    2094     printf("return(NULL)\n");
     2090        psError(__func__, "type %d not supported\n", x->type.type);
     2091    }
     2092
     2093    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
     2094            "return(NULL)\n");
    20952095    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
    20962096            "---- p_psVectorInterpolate() end ----\n");
     2097
    20972098    return(NULL);
    20982099}
     
    21122113                     float x)
    21132114{
     2115    PS_PTR_CHECK_NULL(spline, NAN);
     2116    PS_INT_CHECK_NON_NEGATIVE(spline->n, NAN);
     2117
    21142118    psS32 binNum;
    21152119    psS32 n;
     
    21382142                               const psSpline1D *spline)
    21392143{
     2144    PS_PTR_CHECK_NULL(spline, NULL);
     2145    PS_VECTOR_CHECK_NULL(x, NULL);
     2146    PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL);
     2147
    21402148    psS32 i;
    21412149    psVector *tmpVector;
  • trunk/psLib/src/math/psConstants.h

    r2217 r2218  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-10-27 21:06:30 $
     8 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-10-27 21:25:52 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636}
    3737
     38#define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \
     39if ((NAME1 - NAME2) < -FLT_EPSILON) { \
     40    psError(__func__,"%s is less than %s.", #NAME1, #NAME2); \
     41    return(RVAL); \
     42}
     43
    3844
    3945
     
    5460}
    5561
     62#define PS_PTR_CHECK_SIZE_EQUAL(PTR1, PTR2, RVAL) \
     63if (PTR1->n != PTR2->n) { \
     64    psError(__func__,"ptr %s has size %d, ptr %s has size %d.", #PTR1, PTR1->n, #PTR2, PTR2->n); \
     65    return(RVAL); \
     66}
     67
     68#define PS_PTR_CHECK_TYPE_EQUAL(PTR1, PTR2, RVAL) \
     69if (PTR1->type.type != PTR2->type.type) { \
     70    psError(__func__,"ptr %s has type %d, ptr %s has type %d.", #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \
     71    return(RVAL); \
     72}
    5673
    5774
  • trunk/psLib/src/math/psPolynomial.c

    r2217 r2218  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-27 21:06:30 $
     9 *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-27 21:25:52 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    16881688                            float max)
    16891689{
     1690    PS_INT_CHECK_NON_NEGATIVE(numSplines, NULL);
     1691    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     1692    PS_FLOAT_COMPARE(max, min, NULL);
     1693
    16901694    psSpline1D *tmp = NULL;
    16911695    psS32 i;
    16921696    float tmpDomain;
    16931697    float width;
    1694 
    1695     if (fabs(max-min) < FLT_EPSILON) {
    1696         psLogMsg(__func__, PS_LOG_WARN, "min and max are the same.\n");
    1697         return(NULL);
    1698     }
    16991698
    17001699    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
     
    17531752                                   psS32 order)
    17541753{
     1754    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     1755    PS_VECTOR_CHECK_NULL(bounds, NULL);
     1756    PS_VECTOR_CHECK_EMPTY(bounds, NULL);
     1757
    17551758    psSpline1D *tmp = NULL;
    17561759    psS32 i;
     
    18981901                          psScalar *x)
    18991902{
    1900     if (x->type.type != bins->type.type) {
    1901         psError(__func__, "x->type.type != bins->type.type");
    1902         return(-2);
    1903     }
     1903    PS_PTR_CHECK_TYPE_EQUAL(x, bins, -2);
    19041904
    19051905    if (x->type.type == PS_TYPE_S32) {
     
    19271927                               float x)
    19281928{
     1929    PS_INT_CHECK_NON_NEGATIVE(n, NAN);
     1930    PS_PTR_CHECK_NULL(domain, NAN);
     1931    PS_PTR_CHECK_NULL(range, NAN);
     1932
    19291933    psS32 i;
    19301934    psS32 m;
     
    20372041                                psScalar *x)
    20382042{
     2043    PS_VECTOR_CHECK_NULL(domain, NULL);
     2044    PS_VECTOR_CHECK_NULL(range, NULL);
     2045    PS_PTR_CHECK_NULL(x, NULL);
     2046    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     2047    PS_VECTOR_CHECK_SIZE_EQUAL(domain, range, NULL);
     2048    PS_PTR_CHECK_TYPE_EQUAL(domain, range, NULL);
     2049    PS_PTR_CHECK_TYPE_EQUAL(domain, x, NULL);
     2050
    20392051    psVector *range32 = NULL;
    20402052    psVector *domain32 = NULL;
     
    20422054            "---- p_psVectorInterpolate() begin ----\n");
    20432055
    2044     if ((domain->type.type != range->type.type) ||
    2045             (domain->type.type != x->type.type)) {
    2046         // XXX psError
    2047         printf("p_psVectorInterpolate(): domain->type.type != range->type.type != x->type.type\n");
    2048         printf("%d %d %d\n", domain->type.type, range->type.type, x->type.type);
    2049         exit(1);
    2050     }
    2051     if (domain->n != range->n) {
    2052         // XXX psError
    2053         printf("domain->n != range->n\n");
    2054         exit(1);
    2055     }
    20562056    if (order > (domain->n - 1)) {
    2057         // XXX psError: not enough data points for order-order interpolation.
    2058         printf("not enough data points for order-order interpolation.\n");
    2059         exit(1);
     2057        psError(__func__, "not enough data points for %d-order interpolation.\n", order);
     2058        return(NULL);
    20602059    }
    20612060
     
    20892088    } else {
    20902089        // XXX psError: type not supported
    2091         printf("XXX psError: type not supported\n");
    2092     }
    2093 
    2094     printf("return(NULL)\n");
     2090        psError(__func__, "type %d not supported\n", x->type.type);
     2091    }
     2092
     2093    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
     2094            "return(NULL)\n");
    20952095    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
    20962096            "---- p_psVectorInterpolate() end ----\n");
     2097
    20972098    return(NULL);
    20982099}
     
    21122113                     float x)
    21132114{
     2115    PS_PTR_CHECK_NULL(spline, NAN);
     2116    PS_INT_CHECK_NON_NEGATIVE(spline->n, NAN);
     2117
    21142118    psS32 binNum;
    21152119    psS32 n;
     
    21382142                               const psSpline1D *spline)
    21392143{
     2144    PS_PTR_CHECK_NULL(spline, NULL);
     2145    PS_VECTOR_CHECK_NULL(x, NULL);
     2146    PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL);
     2147
    21402148    psS32 i;
    21412149    psVector *tmpVector;
  • trunk/psLib/src/math/psSpline.c

    r2217 r2218  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-27 21:06:30 $
     9 *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-27 21:25:52 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    16881688                            float max)
    16891689{
     1690    PS_INT_CHECK_NON_NEGATIVE(numSplines, NULL);
     1691    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     1692    PS_FLOAT_COMPARE(max, min, NULL);
     1693
    16901694    psSpline1D *tmp = NULL;
    16911695    psS32 i;
    16921696    float tmpDomain;
    16931697    float width;
    1694 
    1695     if (fabs(max-min) < FLT_EPSILON) {
    1696         psLogMsg(__func__, PS_LOG_WARN, "min and max are the same.\n");
    1697         return(NULL);
    1698     }
    16991698
    17001699    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
     
    17531752                                   psS32 order)
    17541753{
     1754    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     1755    PS_VECTOR_CHECK_NULL(bounds, NULL);
     1756    PS_VECTOR_CHECK_EMPTY(bounds, NULL);
     1757
    17551758    psSpline1D *tmp = NULL;
    17561759    psS32 i;
     
    18981901                          psScalar *x)
    18991902{
    1900     if (x->type.type != bins->type.type) {
    1901         psError(__func__, "x->type.type != bins->type.type");
    1902         return(-2);
    1903     }
     1903    PS_PTR_CHECK_TYPE_EQUAL(x, bins, -2);
    19041904
    19051905    if (x->type.type == PS_TYPE_S32) {
     
    19271927                               float x)
    19281928{
     1929    PS_INT_CHECK_NON_NEGATIVE(n, NAN);
     1930    PS_PTR_CHECK_NULL(domain, NAN);
     1931    PS_PTR_CHECK_NULL(range, NAN);
     1932
    19291933    psS32 i;
    19301934    psS32 m;
     
    20372041                                psScalar *x)
    20382042{
     2043    PS_VECTOR_CHECK_NULL(domain, NULL);
     2044    PS_VECTOR_CHECK_NULL(range, NULL);
     2045    PS_PTR_CHECK_NULL(x, NULL);
     2046    PS_INT_CHECK_NON_NEGATIVE(order, NULL);
     2047    PS_VECTOR_CHECK_SIZE_EQUAL(domain, range, NULL);
     2048    PS_PTR_CHECK_TYPE_EQUAL(domain, range, NULL);
     2049    PS_PTR_CHECK_TYPE_EQUAL(domain, x, NULL);
     2050
    20392051    psVector *range32 = NULL;
    20402052    psVector *domain32 = NULL;
     
    20422054            "---- p_psVectorInterpolate() begin ----\n");
    20432055
    2044     if ((domain->type.type != range->type.type) ||
    2045             (domain->type.type != x->type.type)) {
    2046         // XXX psError
    2047         printf("p_psVectorInterpolate(): domain->type.type != range->type.type != x->type.type\n");
    2048         printf("%d %d %d\n", domain->type.type, range->type.type, x->type.type);
    2049         exit(1);
    2050     }
    2051     if (domain->n != range->n) {
    2052         // XXX psError
    2053         printf("domain->n != range->n\n");
    2054         exit(1);
    2055     }
    20562056    if (order > (domain->n - 1)) {
    2057         // XXX psError: not enough data points for order-order interpolation.
    2058         printf("not enough data points for order-order interpolation.\n");
    2059         exit(1);
     2057        psError(__func__, "not enough data points for %d-order interpolation.\n", order);
     2058        return(NULL);
    20602059    }
    20612060
     
    20892088    } else {
    20902089        // XXX psError: type not supported
    2091         printf("XXX psError: type not supported\n");
    2092     }
    2093 
    2094     printf("return(NULL)\n");
     2090        psError(__func__, "type %d not supported\n", x->type.type);
     2091    }
     2092
     2093    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
     2094            "return(NULL)\n");
    20952095    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
    20962096            "---- p_psVectorInterpolate() end ----\n");
     2097
    20972098    return(NULL);
    20982099}
     
    21122113                     float x)
    21132114{
     2115    PS_PTR_CHECK_NULL(spline, NAN);
     2116    PS_INT_CHECK_NON_NEGATIVE(spline->n, NAN);
     2117
    21142118    psS32 binNum;
    21152119    psS32 n;
     
    21382142                               const psSpline1D *spline)
    21392143{
     2144    PS_PTR_CHECK_NULL(spline, NULL);
     2145    PS_VECTOR_CHECK_NULL(x, NULL);
     2146    PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL);
     2147
    21402148    psS32 i;
    21412149    psVector *tmpVector;
Note: See TracChangeset for help on using the changeset viewer.