IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 13, 2007, 4:36:28 PM (19 years ago)
Author:
magnier
Message:

changing p_psVectorBinDisect to psVectorBinaryDisect, adding psVectorBinaryDisectResult

File:
1 edited

Legend:

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

    r10999 r12434  
    33 *  This file contains standard math routines.
    44 *
    5  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-01-09 22:38:53 $
     5 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-03-14 02:36:28 $
    77 *
    88 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3131#include "psAssert.h"
    3232#include "psConstants.h"
     33#include "psAbort.h"
    3334
    3435/*****************************************************************************/
     
    5556This is a macro covering the various types for the below function.
    5657 *****************************************************************************/
    57 #define VECTOR_BIN_DISECT_CASE(TYPE) \
     58#define VECTOR_BINARY_DISECT_CASE(TYPE) \
    5859case PS_TYPE_##TYPE: { \
    5960    ps##TYPE *bounds = bins->data.TYPE; \
     
    6566    /* psTrace("psLib.math", 6, "Determining the bin for: %f\n", x); */\
    6667    if (value < bounds[0]) { \
    67         psLogMsg(__func__, PS_LOG_WARN, \
    68                  "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
    69                  #TYPE, (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
    70         return(-2); \
     68        psTrace("psLib.math", 3, \
     69                 "psVectorBinaryDisect : ordinate %f is outside vector range (%f - %f).", \
     70                 (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
     71        *status = PS_BINARY_DISECT_OUTSIDE_RANGE; \
     72        return (0); \
    7173    } \
    7274    if (value > bounds[numBins-1]) { \
    73         psLogMsg(__func__, PS_LOG_WARN, \
    74                  "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
    75                  #TYPE, (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
    76         return(-1); \
     75        psTrace("psLib.math", 3, \
     76                 "psVectorBinaryDisect : ordinate %f is outside vector range (%f - %f).", \
     77                 (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
     78        *status = PS_BINARY_DISECT_OUTSIDE_RANGE; \
     79        return (numBins-1); \
    7780    } \
    7881    \
     
    97100
    98101/*****************************************************************************
    99 p_psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data.
     102psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data.
    100103The input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all i).  This routine does a
    101104binary disection of the vector and returns "i" such that (v[i] <= x <= v[i+1).  If x lies outside the range of
    102105v[], then this routine prints a warning message and returns (-2 or -1).
    103106  *****************************************************************************/
    104 psS32 p_psVectorBinDisect(
     107psS32 psVectorBinaryDisect(
     108    psVectorBinaryDisectResult *status,
    105109    const psVector *bins,
    106110    const psScalar *x)
    107111{
    108     PS_ASSERT_VECTOR_NON_NULL(bins, -4);
    109     PS_ASSERT_VECTOR_NON_EMPTY(bins, -4);
    110     PS_ASSERT_PTR_NON_NULL(x, -6);
    111     PS_ASSERT_PTR_TYPE_EQUAL(x, bins, -3);
     112    PS_ASSERT_GENERAL_VECTOR_NON_NULL (bins, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
     113    PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(bins, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
     114    PS_ASSERT_GENERAL_PTR_NON_NULL(x, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
     115    PS_ASSERT_GENERAL_PTR_TYPE_EQUAL(x, bins, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
    112116    long numBins = bins->n;             // Number of bins
    113117
     118    *status = PS_BINARY_DISECT_PASS;
     119
    114120    switch (x->type.type) {
    115         VECTOR_BIN_DISECT_CASE(S8);
    116         VECTOR_BIN_DISECT_CASE(S16);
    117         VECTOR_BIN_DISECT_CASE(S32);
    118         VECTOR_BIN_DISECT_CASE(S64);
    119         VECTOR_BIN_DISECT_CASE(U8);
    120         VECTOR_BIN_DISECT_CASE(U16);
    121         VECTOR_BIN_DISECT_CASE(U32);
    122         VECTOR_BIN_DISECT_CASE(U64);
    123         VECTOR_BIN_DISECT_CASE(F32);
    124         VECTOR_BIN_DISECT_CASE(F64);
     121        VECTOR_BINARY_DISECT_CASE(S8);
     122        VECTOR_BINARY_DISECT_CASE(S16);
     123        VECTOR_BINARY_DISECT_CASE(S32);
     124        VECTOR_BINARY_DISECT_CASE(S64);
     125        VECTOR_BINARY_DISECT_CASE(U8);
     126        VECTOR_BINARY_DISECT_CASE(U16);
     127        VECTOR_BINARY_DISECT_CASE(U32);
     128        VECTOR_BINARY_DISECT_CASE(U64);
     129        VECTOR_BINARY_DISECT_CASE(F32);
     130        VECTOR_BINARY_DISECT_CASE(F64);
    125131    default: {
    126132            char* strType;
    127133            PS_TYPE_NAME(strType, x->type.type);
    128134            psError(PS_ERR_BAD_PARAMETER_TYPE, "psLib type %s is not supported.", strType);
    129             return -1;
     135            *status = PS_BINARY_DISECT_INVALID_TYPE;
     136            return 0;
    130137        }
    131138    }
    132     return(-3);
     139    psAbort ("programming error");
     140    return (0);
    133141}
    134142
     
    151159    } \
    152160    psVector *p = psVectorCopy(NULL, range, PS_TYPE_##TYPE); \
    153     psS32 binNum = p_psVectorBinDisect(domain, x); \
     161    psVectorBinaryDisectResult result; \
     162    psS32 binNum = psVectorBinaryDisect(&result, domain, x); \
    154163    \
    155164    psS32 numIntPoints = order+1; \
Note: See TracChangeset for help on using the changeset viewer.