Changeset 12434 for trunk/psLib/src/math/psMathUtils.c
- Timestamp:
- Mar 13, 2007, 4:36:28 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMathUtils.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMathUtils.c
r10999 r12434 3 3 * This file contains standard math routines. 4 4 * 5 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 1-09 22:38:53$5 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-03-14 02:36:28 $ 7 7 * 8 8 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 31 31 #include "psAssert.h" 32 32 #include "psConstants.h" 33 #include "psAbort.h" 33 34 34 35 /*****************************************************************************/ … … 55 56 This is a macro covering the various types for the below function. 56 57 *****************************************************************************/ 57 #define VECTOR_BIN _DISECT_CASE(TYPE) \58 #define VECTOR_BINARY_DISECT_CASE(TYPE) \ 58 59 case PS_TYPE_##TYPE: { \ 59 60 ps##TYPE *bounds = bins->data.TYPE; \ … … 65 66 /* psTrace("psLib.math", 6, "Determining the bin for: %f\n", x); */\ 66 67 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); \ 71 73 } \ 72 74 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); \ 77 80 } \ 78 81 \ … … 97 100 98 101 /***************************************************************************** 99 p _psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data.102 psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data. 100 103 The input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all i). This routine does a 101 104 binary disection of the vector and returns "i" such that (v[i] <= x <= v[i+1). If x lies outside the range of 102 105 v[], then this routine prints a warning message and returns (-2 or -1). 103 106 *****************************************************************************/ 104 psS32 p_psVectorBinDisect( 107 psS32 psVectorBinaryDisect( 108 psVectorBinaryDisectResult *status, 105 109 const psVector *bins, 106 110 const psScalar *x) 107 111 { 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); 112 116 long numBins = bins->n; // Number of bins 113 117 118 *status = PS_BINARY_DISECT_PASS; 119 114 120 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); 125 131 default: { 126 132 char* strType; 127 133 PS_TYPE_NAME(strType, x->type.type); 128 134 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; 130 137 } 131 138 } 132 return(-3); 139 psAbort ("programming error"); 140 return (0); 133 141 } 134 142 … … 151 159 } \ 152 160 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); \ 154 163 \ 155 164 psS32 numIntPoints = order+1; \
Note:
See TracChangeset
for help on using the changeset viewer.
