Changeset 2273 for trunk/psLib/src/dataManip
- Timestamp:
- Nov 3, 2004, 3:05:00 PM (22 years ago)
- Location:
- trunk/psLib/src/dataManip
- Files:
-
- 10 edited
-
psConstants.h (modified) (14 diffs)
-
psDataManipErrors.dat (modified) (2 diffs)
-
psDataManipErrors.h (modified) (3 diffs)
-
psFunctions.c (modified) (40 diffs)
-
psFunctions.h (modified) (2 diffs)
-
psMatrix.c (modified) (17 diffs)
-
psMatrixVectorArithmetic.c (modified) (34 diffs)
-
psMinimize.c (modified) (8 diffs)
-
psStats.c (modified) (10 diffs)
-
psVectorFFT.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psConstants.h
r2272 r2273 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-11-0 3 22:58:53$8 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-11-04 01:04:57 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #define PS_INT_CHECK_NON_NEGATIVE(NAME, RVAL) \ 33 33 if (NAME < 0) { \ 34 psError(__func__,"Error: %s is less than 0.", #NAME); \ 34 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 35 "Error: %s is less than 0.", #NAME); \ 35 36 return(RVAL); \ 36 37 } … … 38 39 #define PS_INT_CHECK_POSITIVE(NAME, RVAL) \ 39 40 if (NAME < 1) { \ 40 psError(__func__,"Error: %s is 0 or less.", #NAME); \ 41 return(RVAL); \ 42 } 43 44 // Produce an error if ((NAME1 > NAME2) 41 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 42 "Error: %s is 0 or less.", #NAME); \ 43 return(RVAL); \ 44 } 45 46 #define PS_INT_CHECK_RANGE(NAME, LOWER, UPPER, RVAL) \ 47 if ((int)NAME < LOWER || (int)NAME > UPPER) { \ 48 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 49 "Error: %s, %d, is out of range. Must be between %d and %d.", \ 50 #NAME,(int)NAME,LOWER,UPPER); \ 51 return RVAL; \ 52 } 53 54 // Produce an error if (NAME1 > NAME2) 45 55 #define PS_INT_COMPARE(NAME1, NAME2, RVAL) \ 46 56 if (NAME1 > NAME2) { \ 47 psError(__func__,"Error: (%s > %s) (%d %d).", #NAME1, #NAME2, NAME1, NAME2); \ 57 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 58 "Error: (%s > %s) (%d %d).", \ 59 #NAME1, #NAME2, NAME1, NAME2); \ 48 60 return(RVAL); \ 49 61 } … … 53 65 #define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \ 54 66 if (NAME1 > NAME2) { \ 55 psError(__func__,"Error: (%s > %s) (%f %f)", #NAME1, #NAME2, NAME1, NAME2); \ 67 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 68 "Error: (%s > %s) (%f %f)", \ 69 #NAME1, #NAME2, NAME1, NAME2); \ 56 70 return(RVAL); \ 57 71 } … … 59 73 #define PS_FLOAT_CHECK_NON_EQUAL(NAME1, NAME2, RVAL) \ 60 74 if (fabs(NAME2 - NAME1) < FLT_EPSILON) { \ 61 psError(__func__,"Error: %s and %s are equal.", #NAME1, #NAME2); \ 75 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 76 "Error: %s and %s are equal.", \ 77 #NAME1, #NAME2); \ 62 78 return(RVAL); \ 63 79 } … … 67 83 the wrong type. 68 84 *****************************************************************************/ 69 #define PS_PTR_CHECK_NULL(NAME, RVAL) \ 85 #define PS_PTR_CHECK_NULL(NAME, RVAL) PS_PTR_CHECK_NULL_GENERAL(NAME, return RVAL) 86 #define PS_PTR_CHECK_NULL_GENERAL(NAME, CLEANUP) \ 70 87 if (NAME == NULL) { \ 71 psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \ 72 return(RVAL); \ 88 psError(PS_ERR_BAD_PARAMETER_NULL, true, \ 89 "Unallowable operation: %s is NULL.", \ 90 #NAME); \ 91 CLEANUP; \ 73 92 } 74 93 75 94 #define PS_PTR_CHECK_TYPE(NAME, TYPE, RVAL) \ 76 95 if (NAME->type.type != TYPE) { \ 77 psError(__func__,"Unallowable operation: %s has incorrect type.", #NAME); \ 78 return(RVAL); \ 79 } 96 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 97 "Unallowable operation: %s has incorrect type.", \ 98 #NAME); \ 99 return(RVAL); \ 100 } 101 102 #define PS_PTR_CHECK_DIMEN(NAME, DIMEN, RVAL) PS_PTR_CHECK_DIMEN_GENERAL(NAME, DIMEN, return RVAL) 103 #define PS_PTR_CHECK_DIMEN_GENERAL(NAME, DIMEN, CLEANUP) \ 104 if (NAME->type.dimen != DIMEN) { \ 105 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 106 "Unallowable operation: %s has incorrect dimensionality.", \ 107 #NAME); \ 108 CLEANUP; \ 109 } 110 80 111 81 112 #define PS_PTR_CHECK_SIZE_EQUAL(PTR1, PTR2, RVAL) \ 82 113 if (PTR1->n != PTR2->n) { \ 83 psError(__func__,"ptr %s has size %d, ptr %s has size %d.", #PTR1, PTR1->n, #PTR2, PTR2->n); \ 84 return(RVAL); \ 85 } 86 87 #define PS_PTR_CHECK_TYPE_EQUAL(PTR1, PTR2, RVAL) \ 114 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 115 "ptr %s has size %d, ptr %s has size %d.", \ 116 #PTR1, PTR1->n, #PTR2, PTR2->n); \ 117 return(RVAL); \ 118 } 119 120 #define PS_PTR_CHECK_TYPE_EQUAL(PTR1, PTR2, RVAL) PS_PTR_CHECK_TYPE_EQUAL_GENERAL(PTR1, PTR2, return RVAL) 121 122 #define PS_PTR_CHECK_TYPE_EQUAL_GENERAL(PTR1, PTR2, CLEANUP) \ 88 123 if (PTR1->type.type != PTR2->type.type) { \ 89 psError(__func__,"ptr %s has type %d, ptr %s has type %d.", #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \ 90 return(RVAL); \ 124 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 125 "ptr %s has type %d, ptr %s has type %d.", \ 126 #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \ 127 CLEANUP; \ 91 128 } 92 129 … … 95 132 PS_VECTOR macros: 96 133 *****************************************************************************/ 97 #define PS_VECTOR_CHECK_NULL(NAME, RVAL) \ 134 #define PS_VECTOR_CHECK_NULL(NAME, RVAL) PS_VECTOR_CHECK_NULL_GENERAL(NAME, return RVAL) 135 #define PS_VECTOR_CHECK_NULL_GENERAL(NAME, CLEANUP) \ 98 136 if (NAME == NULL || NAME->data.V == NULL) { \ 99 psError(__func__,"Unallowable operation: psVector %s or its data is NULL.", #NAME); \ 100 return(RVAL); \ 137 psError(PS_ERR_BAD_PARAMETER_NULL, true, \ 138 "Unallowable operation: psVector %s or its data is NULL.", \ 139 #NAME); \ 140 CLEANUP; \ 101 141 } \ 102 142 103 143 #define PS_VECTOR_CHECK_EMPTY(NAME, RVAL) \ 104 144 if (NAME->n < 1) { \ 105 psError(__func__,"Unallowable operation: psVector %s has no elements.", #NAME); \ 145 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 146 "Unallowable operation: psVector %s has no elements.", \ 147 #NAME); \ 106 148 return(RVAL); \ 107 149 } \ … … 109 151 #define PS_VECTOR_CHECK_TYPE_F32_OR_F64(NAME, RVAL) \ 110 152 if ((NAME->type.type != PS_TYPE_F32) && (NAME->type.type != PS_TYPE_F64)) { \ 111 psError(__func__, "psVector %s: bad type(%d)", #NAME, NAME->type.type); \ 153 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 154 "psVector %s: bad type(%d)", \ 155 #NAME, NAME->type.type); \ 112 156 return(RVAL); \ 113 157 } \ … … 115 159 #define PS_VECTOR_CHECK_TYPE(NAME, TYPE, RVAL) \ 116 160 if (NAME->type.type != TYPE) { \ 117 psError(__func__,"Unallowable operation: psVector %s has incorrect type.", #NAME); \ 161 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 162 "Unallowable operation: psVector %s has incorrect type.", \ 163 #NAME); \ 118 164 return(RVAL); \ 119 165 } … … 121 167 #define PS_VECTOR_CHECK_SIZE_EQUAL(VEC1, VEC2, RVAL) \ 122 168 if (VEC1->n != VEC2->n) { \ 123 psError(__func__,"psVector %s has size %d, psVector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \ 169 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 170 "psVector %s has size %d, psVector %s has size %d.", \ 171 #VEC1, VEC1->n, #VEC2, VEC2->n); \ 124 172 return(RVAL); \ 125 173 } … … 221 269 #define PS_POLY_CHECK_NULL(NAME, RVAL) \ 222 270 if (NAME == NULL || NAME->coeff == NULL) { \ 223 psError(__func__,"Unallowable operation: polynomial %s or its coeffs is NULL.", #NAME); \ 271 psError(PS_ERR_BAD_PARAMETER_NULL, true, \ 272 "Unallowable operation: polynomial %s or its coeffs is NULL.", \ 273 #NAME); \ 224 274 return(RVAL); \ 225 275 } \ … … 227 277 #define PS_POLY_CHECK_TYPE(NAME, TYPE, RVAL) \ 228 278 if (NAME->type != TYPE) { \ 229 psError(__func__,"Unallowable operation: polynomial %s has wrong type.", #NAME); \ 279 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 280 "Unallowable operation: polynomial %s has wrong type.", #NAME); \ 230 281 return(RVAL); \ 231 282 } \ … … 234 285 PS_IMAGE macros: 235 286 *****************************************************************************/ 236 #define PS_IMAGE_CHECK_NULL(NAME, RVAL) \ 287 #define PS_IMAGE_CHECK_NULL(NAME, RVAL) PS_IMAGE_CHECK_NULL_GENERAL(NAME, return RVAL) 288 #define PS_IMAGE_CHECK_NULL_GENERAL(NAME, CLEANUP) \ 237 289 if (NAME == NULL || NAME->data.V == NULL) { \ 238 psError(__func__,"Unallowable operation: psImage %s or its data is NULL.", #NAME); \ 239 return(RVAL); \ 240 } 241 242 #define PS_IMAGE_CHECK_EMPTY(NAME, RVAL) \ 290 psError(PS_ERR_BAD_PARAMETER_NULL, true, \ 291 "Unallowable operation: psImage %s or its data is NULL.", \ 292 #NAME); \ 293 CLEANUP; \ 294 } 295 296 #define PS_IMAGE_CHECK_EMPTY(NAME, RVAL) PS_IMAGE_CHECK_EMPTY_GENERAL(NAME, return RVAL) 297 #define PS_IMAGE_CHECK_EMPTY_GENERAL(NAME, CLEANUP) \ 243 298 if (NAME->numCols < 1 || NAME->numRows < 1) { \ 244 psError(__func__,"Unallowable operation: psImage %s has zero rows or columns (%dx%d).", #NAME, \ 245 NAME->numCols, NAME->numRows); \ 246 return(RVAL); \ 299 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 300 "Unallowable operation: psImage %s has zero rows or columns (%dx%d).", \ 301 #NAME, NAME->numCols, NAME->numRows); \ 302 CLEANUP; \ 247 303 } 248 304 249 305 #define PS_IMAGE_CHECK_TYPE(NAME, TYPE, RVAL) \ 250 306 if (NAME->type.type != TYPE) { \ 251 psError(__func__,"Unallowable operation: psImage %s has incorrect type.", #NAME); \ 307 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 308 "Unallowable operation: psImage %s has incorrect type.", \ 309 #NAME); \ 252 310 return(RVAL); \ 253 311 } … … 260 318 #define PS_READOUT_CHECK_NULL(NAME, RVAL) \ 261 319 if (NAME == NULL || NAME->image == NULL) { \ 262 psError(__func__,"Unallowable operation: psReadout %s or its data is NULL.", #NAME); \ 320 psError(PS_ERR_BAD_PARAMETER_NULL, true, \ 321 "Unallowable operation: psReadout %s or its data is NULL.", \ 322 #NAME); \ 263 323 return(RVAL); \ 264 324 } -
trunk/psLib/src/dataManip/psDataManipErrors.dat
r2080 r2273 8 8 #################################################################### 9 9 # 10 psVectorFFT_ IMAGE_TYPE_UNSUPPORTEDInput psVector type, %s, is not supported. Valid data types are psF32 and psC32.10 psVectorFFT_TYPE_NOT_F32_C32 Input psVector type, %s, is not supported. Valid data types are psF32 and psC32. 11 11 psVectorFFT_REVERSE_NOT_COMPLEX Input psVector (%s) is not complex. Reverse FFT operation requires a complex input. 12 12 psVectorFFT_FORWARD_NOT_REAL Input psVector (%s) is not real. Forward FFT operation requires a real input. … … 18 18 psVectorFFT_NONCOMPLEX_NOTSUPPORTED Input psVector type, %s, is required to be either psC32 or psC64. 19 19 psVectorFFT_DIRECTION_NOTSET Must specify the direction as either PS_FFT_FORWARD or PS_FFT_REVERSE. 20 # 21 psStats_NOT_F32_F64 Invalid data type, %s. Only psF32 and psF64 data types are supported. 22 psStats_VECTOR_TYPE_UNSUPPORTED Input psVector type, %s, is not supported. 23 psStats_YVAL_OUT_OF_RANGE Specified yVal, %g, is not within y-range, %g to %g. 24 psStats_ROBUST_QUARTILE_BINS_FAILED Could not determine the robust lower/upper quartile bin numbers. 25 psStats_STATS_FAILED Failed to calculate the specified statistic. 26 # 27 psFunctions_INVALID_POLYNOMIAL_TYPE Unknown polynomial type 0x%x found. Evaluation failed. 28 psFunctions_TYPE_NOT_SUPPORTED Input psVector type, %s, is not supported. 29 psFunctions_NOT_ENOUGH_DATAPOINTS Given vector does not have enough data points for %d-order interpolation. 30 # 31 psMatrix_COUNT_DIFFERS Number of elements inconsistent, %d vs %d. Number of elements must match. 32 psMatrix_IMAGE_SIZE_DIFFERS Specified psImage dimensions differed, %dx%d vs %dx%d. 33 psMatrix_TYPE_MISMATCH Specified data type, %s, is not supported. 34 psMatrix_MIN_COMPLEX_SUPPORT The minimum operation is not supported with complex data. 35 psMatrix_MAX_COMPLEX_SUPPORT The maximum operation is not supported with complex data. 36 psMatrix_OPERATION_UNSUPPORTED Specified operation, %s, is not supported. 37 psMatrix_DIMEN_OTHER_FOUND %s's dimensionality is PS_DIMEN_OTHER, which is not allowed. 38 psMatrix_OUTPUT_VECTOR_NOT_CREATED Couldn't create a proper output psVector. 39 psMatrix_OUTPUT_IMAGE_NOT_CREATED Couldn't create a proper output psImage. 40 psMatrix_DIMEN_INVALID Specified parameter, %s, has invalid dimensionality, %d. 41 psMatrix_VECTOR_EMPTY Input psVector contains no elements. No data to perform operation with. 42 psMatrix_IMAGE_EMPTY Input psImage contains no pixels. No data to perform operation with. -
trunk/psLib/src/dataManip/psDataManipErrors.h
r2080 r2273 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-1 0-13 20:46:57$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-11-04 01:04:59 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 30 31 31 //~Start #define PS_ERRORTEXT_$1 "$2" 32 #define PS_ERRORTEXT_psVectorFFT_ IMAGE_TYPE_UNSUPPORTED"Input psVector type, %s, is not supported. Valid data types are psF32 and psC32."32 #define PS_ERRORTEXT_psVectorFFT_TYPE_NOT_F32_C32 "Input psVector type, %s, is not supported. Valid data types are psF32 and psC32." 33 33 #define PS_ERRORTEXT_psVectorFFT_REVERSE_NOT_COMPLEX "Input psVector (%s) is not complex. Reverse FFT operation requires a complex input." 34 34 #define PS_ERRORTEXT_psVectorFFT_FORWARD_NOT_REAL "Input psVector (%s) is not real. Forward FFT operation requires a real input." … … 40 40 #define PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED "Input psVector type, %s, is required to be either psC32 or psC64." 41 41 #define PS_ERRORTEXT_psVectorFFT_DIRECTION_NOTSET "Must specify the direction as either PS_FFT_FORWARD or PS_FFT_REVERSE." 42 #define PS_ERRORTEXT_psStats_NOT_F32_F64 "Invalid data type, %s. Only psF32 and psF64 data types are supported." 43 #define PS_ERRORTEXT_psStats_VECTOR_TYPE_UNSUPPORTED "Input psVector type, %s, is not supported." 44 #define PS_ERRORTEXT_psStats_YVAL_OUT_OF_RANGE "Specified yVal, %g, is not within y-range, %g to %g." 45 #define PS_ERRORTEXT_psStats_ROBUST_QUARTILE_BINS_FAILED "Could not determine the robust lower/upper quartile bin numbers." 46 #define PS_ERRORTEXT_psStats_STATS_FAILED "Failed to calculate the specified statistic." 47 #define PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE "Unknown polynomial type 0x%x found. Evaluation failed." 48 #define PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED "Input psVector type, %s, is not supported." 49 #define PS_ERRORTEXT_psFunctions_NOT_ENOUGH_DATAPOINTS "Given vector does not have enough data points for %d-order interpolation." 50 #define PS_ERRORTEXT_psMatrix_COUNT_DIFFERS "Number of elements inconsistent, %d vs %d. Number of elements must match." 51 #define PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS "Specified psImage dimensions differed, %dx%d vs %dx%d." 52 #define PS_ERRORTEXT_psMatrix_TYPE_MISMATCH "Specified data type, %s, is not supported." 53 #define PS_ERRORTEXT_psMatrix_MIN_COMPLEX_SUPPORT "The minimum operation is not supported with complex data." 54 #define PS_ERRORTEXT_psMatrix_MAX_COMPLEX_SUPPORT "The maximum operation is not supported with complex data." 55 #define PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED "Specified operation, %s, is not supported." 56 #define PS_ERRORTEXT_psMatrix_DIMEN_OTHER_FOUND "%s's dimensionality is PS_DIMEN_OTHER, which is not allowed." 57 #define PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED "Couldn't create a proper output psVector." 58 #define PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED "Couldn't create a proper output psImage." 59 #define PS_ERRORTEXT_psMatrix_DIMEN_INVALID "Specified parameter, %s, has invalid dimensionality, %d." 60 #define PS_ERRORTEXT_psMatrix_VECTOR_EMPTY "Input psVector contains no elements. No data to perform operation with." 61 #define PS_ERRORTEXT_psMatrix_IMAGE_EMPTY "Input psImage contains no pixels. No data to perform operation with." 42 62 //~End 43 63 -
trunk/psLib/src/dataManip/psFunctions.c
r2224 r2273 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-1 0-28 00:22:53$9 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-11-04 01:04:59 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 #include "psFunctions.h" 36 36 #include "psConstants.h" 37 38 #include "psDataManipErrors.h" 39 37 40 /*****************************************************************************/ 38 41 /* DEFINE STATEMENTS */ … … 50 53 static void dPolynomial3DFree(psDPolynomial3D* myPoly); 51 54 static void dPolynomial4DFree(psDPolynomial4D* myPoly); 55 static void spline1DFree(psSpline1D *tmpSpline); 56 static psS32 vectorBinDisectF32(float *bins,psS32 numBins,float x); 57 static psS32 vectorBinDisectS32(psS32 *bins,psS32 numBins,psS32 x); 52 58 53 59 /*****************************************************************************/ … … 67 73 /*****************************************************************************/ 68 74 75 static void spline1DFree(psSpline1D *tmpSpline) 76 { 77 psS32 i; 78 79 if (tmpSpline == NULL) { 80 return; 81 } 82 83 if (tmpSpline->spline != NULL) { 84 for (i=0;i<tmpSpline->n;i++) { 85 psFree((tmpSpline->spline)[i]); 86 } 87 psFree(tmpSpline->spline); 88 } 89 90 if (tmpSpline->p_psDeriv2 != NULL) { 91 psFree(tmpSpline->p_psDeriv2); 92 } 93 psFree(tmpSpline->domains); 94 95 return; 96 } 97 98 static void polynomial1DFree(psPolynomial1D* myPoly) 99 { 100 psFree(myPoly->coeff); 101 psFree(myPoly->coeffErr); 102 psFree(myPoly->mask); 103 } 104 105 static void polynomial2DFree(psPolynomial2D* myPoly) 106 { 107 psS32 x = 0; 108 109 for (x = 0; x < myPoly->nX; x++) { 110 psFree(myPoly->coeff[x]); 111 psFree(myPoly->coeffErr[x]); 112 psFree(myPoly->mask[x]); 113 } 114 psFree(myPoly->coeff); 115 psFree(myPoly->coeffErr); 116 psFree(myPoly->mask); 117 } 118 119 static void polynomial3DFree(psPolynomial3D* myPoly) 120 { 121 psS32 x = 0; 122 psS32 y = 0; 123 124 for (x = 0; x < myPoly->nX; x++) { 125 for (y = 0; y < myPoly->nY; y++) { 126 psFree(myPoly->coeff[x][y]); 127 psFree(myPoly->coeffErr[x][y]); 128 psFree(myPoly->mask[x][y]); 129 } 130 psFree(myPoly->coeff[x]); 131 psFree(myPoly->coeffErr[x]); 132 psFree(myPoly->mask[x]); 133 } 134 135 psFree(myPoly->coeff); 136 psFree(myPoly->coeffErr); 137 psFree(myPoly->mask); 138 } 139 140 static void polynomial4DFree(psPolynomial4D* myPoly) 141 { 142 psS32 w = 0; 143 psS32 x = 0; 144 psS32 y = 0; 145 146 for (w = 0; w < myPoly->nW; w++) { 147 for (x = 0; x < myPoly->nX; x++) { 148 for (y = 0; y < myPoly->nY; y++) { 149 psFree(myPoly->coeff[w][x][y]); 150 psFree(myPoly->coeffErr[w][x][y]); 151 psFree(myPoly->mask[w][x][y]); 152 } 153 psFree(myPoly->coeff[w][x]); 154 psFree(myPoly->coeffErr[w][x]); 155 psFree(myPoly->mask[w][x]); 156 } 157 psFree(myPoly->coeff[w]); 158 psFree(myPoly->coeffErr[w]); 159 psFree(myPoly->mask[w]); 160 } 161 162 psFree(myPoly->coeff); 163 psFree(myPoly->coeffErr); 164 psFree(myPoly->mask); 165 } 166 167 static void dPolynomial1DFree(psDPolynomial1D* myPoly) 168 { 169 psFree(myPoly->coeff); 170 psFree(myPoly->coeffErr); 171 psFree(myPoly->mask); 172 } 173 174 static void dPolynomial2DFree(psDPolynomial2D* myPoly) 175 { 176 psS32 x = 0; 177 178 for (x = 0; x < myPoly->nX; x++) { 179 psFree(myPoly->coeff[x]); 180 psFree(myPoly->coeffErr[x]); 181 psFree(myPoly->mask[x]); 182 } 183 psFree(myPoly->coeff); 184 psFree(myPoly->coeffErr); 185 psFree(myPoly->mask); 186 } 187 188 static void dPolynomial3DFree(psDPolynomial3D* myPoly) 189 { 190 psS32 x = 0; 191 psS32 y = 0; 192 193 for (x = 0; x < myPoly->nX; x++) { 194 for (y = 0; y < myPoly->nY; y++) { 195 psFree(myPoly->coeff[x][y]); 196 psFree(myPoly->coeffErr[x][y]); 197 psFree(myPoly->mask[x][y]); 198 } 199 psFree(myPoly->coeff[x]); 200 psFree(myPoly->coeffErr[x]); 201 psFree(myPoly->mask[x]); 202 } 203 204 psFree(myPoly->coeff); 205 psFree(myPoly->coeffErr); 206 psFree(myPoly->mask); 207 } 208 209 static void dPolynomial4DFree(psDPolynomial4D* myPoly) 210 { 211 psS32 w = 0; 212 psS32 x = 0; 213 psS32 y = 0; 214 215 for (w = 0; w < myPoly->nW; w++) { 216 for (x = 0; x < myPoly->nX; x++) { 217 for (y = 0; y < myPoly->nY; y++) { 218 psFree(myPoly->coeff[w][x][y]); 219 psFree(myPoly->coeffErr[w][x][y]); 220 psFree(myPoly->mask[w][x][y]); 221 } 222 psFree(myPoly->coeff[w][x]); 223 psFree(myPoly->coeffErr[w][x]); 224 psFree(myPoly->mask[w][x]); 225 } 226 psFree(myPoly->coeff[w]); 227 psFree(myPoly->coeffErr[w]); 228 psFree(myPoly->mask[w]); 229 } 230 231 psFree(myPoly->coeff); 232 psFree(myPoly->coeffErr); 233 psFree(myPoly->mask); 234 } 235 69 236 /***************************************************************************** 70 CreateChebyshevPolys(n): this routine takes as input the required order n,237 createChebyshevPolys(n): this routine takes as input the required order n, 71 238 and returns as output as a pointer to an array of n psPolynomial1D 72 239 structures, corresponding to the first n Chebyshev polynomials. … … 76 243 outer coefficients of the Chebyshev polynomials. 77 244 *****************************************************************************/ 78 static psPolynomial1D ** CreateChebyshevPolys(psS32 maxChebyPoly)245 static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly) 79 246 { 80 247 PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL); … … 103 270 104 271 return (chebPolys); 272 } 273 274 /***************************************************************************** 275 Polynomial coefficients will be accessed in [w][x][y][z] fashion. 276 277 XXX: Should the "coeffErr[]" should be used as well? 278 *****************************************************************************/ 279 static float ordPolynomial1DEval(float x, const psPolynomial1D* myPoly) 280 { 281 psS32 loop_x = 0; 282 float polySum = 0.0; 283 float xSum = 1.0; 284 285 psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4, 286 "---- Calling ordPolynomial1DEval(%f)\n", x); 287 psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4, 288 "Polynomial order is %d\n", myPoly->n); 289 for (loop_x = 0; loop_x < myPoly->n; loop_x++) { 290 psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4, 291 "Polynomial coeff[%d] is %f\n", loop_x, myPoly->coeff[loop_x]); 292 } 293 294 for (loop_x = 0; loop_x < myPoly->n; loop_x++) { 295 if (myPoly->mask[loop_x] == 0) { 296 psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 10, 297 "polysum+= sum*coeff [%f+= (%f * %f)\n", polySum, xSum, myPoly->coeff[loop_x]); 298 polySum += xSum * myPoly->coeff[loop_x]; 299 xSum *= x; 300 } 301 } 302 303 return(polySum); 304 } 305 306 // XXX: You can do this without having to psAlloc() vector d. 307 // XXX: How does the mask vector effect Crenshaw's formula? 308 static float chebPolynomial1DEval(float x, const psPolynomial1D* myPoly) 309 { 310 psVector *d; 311 psS32 n; 312 psS32 i; 313 float tmp; 314 315 n = myPoly->n; 316 d = psVectorAlloc(n, PS_TYPE_F32); 317 d->data.F32[n-1] = myPoly->coeff[n-1]; 318 d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]) + myPoly->coeff[n-2]; 319 for (i=n-3;i>=1;i--) { 320 d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) - 321 (d->data.F32[i+2]) + 322 (myPoly->coeff[i]); 323 } 324 325 tmp = (x * d->data.F32[1]) - 326 (d->data.F32[2]) + 327 (0.5 * myPoly->coeff[0]); 328 329 psFree(d); 330 return(tmp); 331 /* 332 333 psS32 n; 334 psS32 i; 335 float tmp; 336 psPolynomial1D **chebPolys = NULL; 337 338 n = myPoly->n; 339 chebPolys = createChebyshevPolys(n); 340 341 tmp = 0.0; 342 for (i=0;i<myPoly->n;i++) { 343 tmp+= (myPoly->coeff[i] * psPolynomial1DEval(x, chebPolys[i])); 344 // printf("HMMM: psPolynomial1DEval(%f, chebPolys[%d]) is %f\n", x, i, psPolynomial1DEval(x, chebPolys[i])); 345 } 346 tmp-= (myPoly->coeff[0]/2.0); 347 348 349 return(tmp); 350 */ 351 } 352 353 static float ordPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 354 { 355 PS_POLY_CHECK_NULL(myPoly, NAN); 356 357 psS32 loop_x = 0; 358 psS32 loop_y = 0; 359 float polySum = 0.0; 360 float xSum = 1.0; 361 float ySum = 1.0; 362 363 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 364 ySum = xSum; 365 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 366 if (myPoly->mask[loop_x][loop_y] == 0) { 367 polySum += ySum * myPoly->coeff[loop_x][loop_y]; 368 ySum *= y; 369 } 370 } 371 xSum *= x; 372 } 373 374 return(polySum); 375 } 376 377 static float chebPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 378 { 379 PS_POLY_CHECK_NULL(myPoly, NAN); 380 381 psS32 loop_x = 0; 382 psS32 loop_y = 0; 383 psS32 i = 0; 384 float polySum = 0.0; 385 psPolynomial1D* *chebPolys = NULL; 386 psS32 maxChebyPoly = 0; 387 388 // Determine how many Chebyshev polynomials 389 // are needed, then create them. 390 maxChebyPoly = myPoly->nX; 391 if (myPoly->nY > maxChebyPoly) { 392 maxChebyPoly = myPoly->nY; 393 } 394 chebPolys = createChebyshevPolys(maxChebyPoly); 395 396 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 397 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 398 if (myPoly->mask[loop_x][loop_y] == 0) { 399 polySum += myPoly->coeff[loop_x][loop_y] * 400 psPolynomial1DEval(x, chebPolys[loop_x]) * 401 psPolynomial1DEval(y, chebPolys[loop_y]); 402 } 403 } 404 } 405 for (i=0;i<maxChebyPoly;i++) { 406 psFree(chebPolys[i]); 407 } 408 psFree(chebPolys); 409 return(polySum); 410 } 411 412 static float ordPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly) 413 { 414 psS32 loop_x = 0; 415 psS32 loop_y = 0; 416 psS32 loop_z = 0; 417 float polySum = 0.0; 418 float xSum = 1.0; 419 float ySum = 1.0; 420 float zSum = 1.0; 421 422 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 423 ySum = xSum; 424 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 425 zSum = ySum; 426 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 427 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) { 428 polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z]; 429 zSum *= z; 430 } 431 } 432 ySum *= y; 433 } 434 xSum *= x; 435 } 436 437 return(polySum); 438 } 439 440 static float chebPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly) 441 { 442 psS32 loop_x = 0; 443 psS32 loop_y = 0; 444 psS32 loop_z = 0; 445 psS32 i = 0; 446 float polySum = 0.0; 447 psPolynomial1D* *chebPolys = NULL; 448 psS32 maxChebyPoly = 0; 449 450 // Determine how many Chebyshev polynomials 451 // are needed, then create them. 452 maxChebyPoly = myPoly->nX; 453 if (myPoly->nY > maxChebyPoly) { 454 maxChebyPoly = myPoly->nY; 455 } 456 if (myPoly->nZ > maxChebyPoly) { 457 maxChebyPoly = myPoly->nZ; 458 } 459 chebPolys = createChebyshevPolys(maxChebyPoly); 460 461 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 462 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 463 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 464 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) { 465 polySum += myPoly->coeff[loop_x][loop_y][loop_z] * 466 psPolynomial1DEval(x, chebPolys[loop_x]) * 467 psPolynomial1DEval(y, chebPolys[loop_y]) * 468 psPolynomial1DEval(z, chebPolys[loop_z]); 469 } 470 } 471 } 472 } 473 474 for (i=0;i<maxChebyPoly;i++) { 475 psFree(chebPolys[i]); 476 } 477 psFree(chebPolys); 478 return(polySum); 479 } 480 481 static float ordPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly) 482 { 483 psS32 loop_w = 0; 484 psS32 loop_x = 0; 485 psS32 loop_y = 0; 486 psS32 loop_z = 0; 487 float polySum = 0.0; 488 float wSum = 1.0; 489 float xSum = 1.0; 490 float ySum = 1.0; 491 float zSum = 1.0; 492 493 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) { 494 xSum = wSum; 495 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 496 ySum = xSum; 497 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 498 zSum = ySum; 499 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 500 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) { 501 polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z]; 502 zSum *= z; 503 } 504 } 505 ySum *= y; 506 } 507 xSum *= x; 508 } 509 wSum *= w; 510 } 511 512 return(polySum); 513 } 514 515 static float chebPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly) 516 { 517 psS32 loop_w = 0; 518 psS32 loop_x = 0; 519 psS32 loop_y = 0; 520 psS32 loop_z = 0; 521 psS32 i = 0; 522 float polySum = 0.0; 523 psPolynomial1D* *chebPolys = NULL; 524 psS32 maxChebyPoly = 0; 525 526 // Determine how many Chebyshev polynomials 527 // are needed, then create them. 528 maxChebyPoly = myPoly->nW; 529 if (myPoly->nX > maxChebyPoly) { 530 maxChebyPoly = myPoly->nX; 531 } 532 if (myPoly->nY > maxChebyPoly) { 533 maxChebyPoly = myPoly->nY; 534 } 535 if (myPoly->nZ > maxChebyPoly) { 536 maxChebyPoly = myPoly->nZ; 537 } 538 chebPolys = createChebyshevPolys(maxChebyPoly); 539 540 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) { 541 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 542 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 543 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 544 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) { 545 polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] * 546 psPolynomial1DEval(w, chebPolys[loop_w]) * 547 psPolynomial1DEval(x, chebPolys[loop_x]) * 548 psPolynomial1DEval(y, chebPolys[loop_y]) * 549 psPolynomial1DEval(z, chebPolys[loop_z]); 550 } 551 } 552 } 553 } 554 } 555 556 for (i=0;i<maxChebyPoly;i++) { 557 psFree(chebPolys[i]); 558 } 559 psFree(chebPolys); 560 return(polySum); 561 } 562 563 /***************************************************************************** 564 Polynomial coefficients will be accessed in [w][x][y][z] fashion. 565 *****************************************************************************/ 566 static double dOrdPolynomial1DEval(double x, const psDPolynomial1D* myPoly) 567 { 568 psS32 loop_x = 0; 569 double polySum = 0.0; 570 double xSum = 1.0; 571 572 for (loop_x = 0; loop_x < myPoly->n; loop_x++) { 573 if (myPoly->mask[loop_x] == 0) { 574 polySum += xSum * myPoly->coeff[loop_x]; 575 xSum *= x; 576 } 577 } 578 579 return(polySum); 580 } 581 582 // XXX: You can do this without having to psAlloc() vector d. 583 // XXX: How does the mask vector effect Crenshaw's formula? 584 static double dChebPolynomial1DEval(double x, const psDPolynomial1D* myPoly) 585 { 586 psVector *d; 587 psS32 n; 588 psS32 i; 589 double tmp; 590 591 n = myPoly->n; 592 d = psVectorAlloc(n, PS_TYPE_F64); 593 d->data.F64[n-1] = myPoly->coeff[n-1]; 594 d->data.F64[n-2] = (2.0 * x * d->data.F64[n-1]) + myPoly->coeff[n-2]; 595 for (i=n-3;i>=1;i--) { 596 d->data.F64[i] = (2.0 * x * d->data.F64[i+1]) - 597 (d->data.F64[i+2]) + 598 (myPoly->coeff[i]); 599 } 600 601 tmp = (x * d->data.F64[1]) - 602 (d->data.F64[2]) + 603 (0.5 * myPoly->coeff[0]); 604 605 psFree(d); 606 return(tmp); 607 } 608 609 static double dOrdPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly) 610 { 611 psS32 loop_x = 0; 612 psS32 loop_y = 0; 613 double polySum = 0.0; 614 double xSum = 1.0; 615 double ySum = 1.0; 616 617 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 618 ySum = xSum; 619 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 620 if (myPoly->mask[loop_x][loop_y] == 0) { 621 polySum += ySum * myPoly->coeff[loop_x][loop_y]; 622 ySum *= y; 623 } 624 } 625 xSum *= x; 626 } 627 628 return(polySum); 629 } 630 631 static double dChebPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly) 632 { 633 psS32 loop_x = 0; 634 psS32 loop_y = 0; 635 psS32 i = 0; 636 double polySum = 0.0; 637 psPolynomial1D* *chebPolys = NULL; 638 psS32 maxChebyPoly = 0; 639 640 // Determine how many Chebyshev polynomials 641 // are needed, then create them. 642 maxChebyPoly = myPoly->nX; 643 if (myPoly->nY > maxChebyPoly) { 644 maxChebyPoly = myPoly->nY; 645 } 646 chebPolys = createChebyshevPolys(maxChebyPoly); 647 648 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 649 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 650 if (myPoly->mask[loop_x][loop_y] == 0) { 651 polySum += myPoly->coeff[loop_x][loop_y] * 652 psPolynomial1DEval(x, chebPolys[loop_x]) * 653 psPolynomial1DEval(y, chebPolys[loop_y]); 654 } 655 } 656 } 657 658 for (i=0;i<maxChebyPoly;i++) { 659 psFree(chebPolys[i]); 660 } 661 psFree(chebPolys); 662 return(polySum); 663 } 664 665 static double dOrdPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly) 666 { 667 psS32 loop_x = 0; 668 psS32 loop_y = 0; 669 psS32 loop_z = 0; 670 double polySum = 0.0; 671 double xSum = 1.0; 672 double ySum = 1.0; 673 double zSum = 1.0; 674 675 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 676 ySum = xSum; 677 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 678 zSum = ySum; 679 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 680 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) { 681 polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z]; 682 zSum *= z; 683 } 684 } 685 ySum *= y; 686 } 687 xSum *= x; 688 } 689 690 return(polySum); 691 } 692 693 static double dChebPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly) 694 { 695 psS32 loop_x = 0; 696 psS32 loop_y = 0; 697 psS32 loop_z = 0; 698 psS32 i = 0; 699 double polySum = 0.0; 700 psPolynomial1D* *chebPolys = NULL; 701 psS32 maxChebyPoly = 0; 702 703 // Determine how many Chebyshev polynomials 704 // are needed, then create them. 705 maxChebyPoly = myPoly->nX; 706 if (myPoly->nY > maxChebyPoly) { 707 maxChebyPoly = myPoly->nY; 708 } 709 if (myPoly->nZ > maxChebyPoly) { 710 maxChebyPoly = myPoly->nZ; 711 } 712 chebPolys = createChebyshevPolys(maxChebyPoly); 713 714 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 715 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 716 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 717 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) { 718 polySum += myPoly->coeff[loop_x][loop_y][loop_z] * 719 psPolynomial1DEval(x, chebPolys[loop_x]) * 720 psPolynomial1DEval(y, chebPolys[loop_y]) * 721 psPolynomial1DEval(z, chebPolys[loop_z]); 722 } 723 } 724 } 725 } 726 727 for (i=0;i<maxChebyPoly;i++) { 728 psFree(chebPolys[i]); 729 } 730 psFree(chebPolys); 731 return(polySum); 732 } 733 734 static double dOrdPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly) 735 { 736 psS32 loop_w = 0; 737 psS32 loop_x = 0; 738 psS32 loop_y = 0; 739 psS32 loop_z = 0; 740 double polySum = 0.0; 741 double wSum = 1.0; 742 double xSum = 1.0; 743 double ySum = 1.0; 744 double zSum = 1.0; 745 746 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) { 747 xSum = wSum; 748 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 749 ySum = xSum; 750 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 751 zSum = ySum; 752 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 753 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) { 754 polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z]; 755 zSum *= z; 756 } 757 } 758 ySum *= y; 759 } 760 xSum *= x; 761 } 762 wSum *= w; 763 } 764 765 return(polySum); 766 } 767 768 static double dChebPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly) 769 { 770 psS32 loop_w = 0; 771 psS32 loop_x = 0; 772 psS32 loop_y = 0; 773 psS32 loop_z = 0; 774 psS32 i = 0; 775 double polySum = 0.0; 776 psPolynomial1D* *chebPolys = NULL; 777 psS32 maxChebyPoly = 0; 778 779 // Determine how many Chebyshev polynomials 780 // are needed, then create them. 781 maxChebyPoly = myPoly->nW; 782 if (myPoly->nX > maxChebyPoly) { 783 maxChebyPoly = myPoly->nX; 784 } 785 if (myPoly->nY > maxChebyPoly) { 786 maxChebyPoly = myPoly->nY; 787 } 788 if (myPoly->nZ > maxChebyPoly) { 789 maxChebyPoly = myPoly->nZ; 790 } 791 chebPolys = createChebyshevPolys(maxChebyPoly); 792 793 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) { 794 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) { 795 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) { 796 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) { 797 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) { 798 polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] * 799 psPolynomial1DEval(w, chebPolys[loop_w]) * 800 psPolynomial1DEval(x, chebPolys[loop_x]) * 801 psPolynomial1DEval(y, chebPolys[loop_y]) * 802 psPolynomial1DEval(z, chebPolys[loop_z]); 803 } 804 } 805 } 806 } 807 } 808 809 for (i=0;i<maxChebyPoly;i++) { 810 psFree(chebPolys[i]); 811 } 812 psFree(chebPolys); 813 return(polySum); 814 } 815 816 817 /***************************************************************************** 818 p_psInterpolate1D(): This routine will take as input n-element floating 819 point arrays domain and range, and the x value, assumed to lie with the 820 domain vector. It produces as output the (n-1)-order LaGrange interpolated 821 value of x. 822 823 XXX: do we error check for non-distinct domain values? 824 *****************************************************************************/ 825 static float fullInterpolate1DF32(float *domain, 826 float *range, 827 psS32 n, 828 float x) 829 { 830 PS_INT_CHECK_NON_NEGATIVE(n, NAN); 831 PS_PTR_CHECK_NULL(domain, NAN); 832 PS_PTR_CHECK_NULL(range, NAN); 833 834 psS32 i; 835 psS32 m; 836 static psVector *p = NULL; 837 p = psVectorRecycle(p, n, PS_TYPE_F32); 838 p_psMemSetPersistent(p, true); 839 p_psMemSetPersistent(p->data.F32, true); 840 /* 841 psVector *p = psVectorAlloc(n, PS_TYPE_F32); 842 float tmp; 843 */ 844 845 psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 4, 846 "---- fullInterpolate1DF32() begin (%d-order at x=%f) (%d data points)----\n", n-1, x, n); 847 848 for (i=0;i<n;i++) { 849 psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 6, 850 "domain/range is (%f %f)\n", domain[i], range[i]); 851 } 852 853 for (i=0;i<n;i++) { 854 p->data.F32[i] = range[i]; 855 psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 6, 856 "p->data.F32[%d] is %f\n", i, p->data.F32[i]); 857 858 } 859 860 // From NR, during each iteration of the m loop, we are computing the 861 // p_{i ... i+m} terms. 862 for (m=1;m<n;m++) { 863 for (i=0;i<n-m;i++) { 864 // From NR: we are computing P_{i ... i+m} 865 p->data.F32[i] = (((x-domain[i+m]) * p->data.F32[i]) + 866 ((domain[i]-x) * p->data.F32[i+1])) / 867 (domain[i] - domain[i+m]); 868 //printf("((%f-%f * %f) + (%f-%f * %f)) / (%f - %f)\n", x, domain[i+m], p->data.F32[i], domain[i], x, p->data.F32[i+1], domain[i], domain[i+m]); 869 psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 6, 870 "p->data.F32[%d] is %f\n", i, p->data.F32[i]); 871 } 872 } 873 psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 4, 874 "---- fullInterpolate1DF32() end ----\n"); 875 876 /* 877 tmp = p->data.F32[0]; 878 psFree(p); 879 return(tmp); 880 */ 881 return(p->data.F32[0]); 882 } 883 884 885 /***************************************************************************** 886 interpolate1DF32(): this is the base 1-D flat memory routine to perform 887 LaGrange interpolation. 888 *****************************************************************************/ 889 static float interpolate1DF32(float *domain, 890 float *range, 891 psS32 n, 892 psS32 order, 893 float x) 894 { 895 psS32 binNum; 896 psS32 numIntPoints = order+1; 897 psS32 origin; 898 899 psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4, 900 "---- interpolate1DF32() begin ----\n"); 901 902 binNum = vectorBinDisectF32(domain, n, x); 903 904 if (0 == numIntPoints%2) { 905 origin = binNum - ((numIntPoints/2) - 1); 906 } else { 907 origin = binNum - (numIntPoints/2); 908 if ((x-domain[binNum]) > (domain[binNum+1]-x)) { 909 // x is closer to binNum+1. 910 origin = 1 + (binNum - (numIntPoints/2)); 911 } 912 } 913 if (origin < 0) { 914 origin = 0; 915 } 916 if ((origin + numIntPoints) > n) { 917 origin = n - numIntPoints; 918 } 919 920 psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4, 921 "---- interpolate1DF32() end ----\n"); 922 return(fullInterpolate1DF32(&domain[origin], &range[origin], order+1, x)); 105 923 } 106 924 … … 336 1154 } 337 1155 338 static void polynomial1DFree(psPolynomial1D* myPoly)339 {340 psFree(myPoly->coeff);341 psFree(myPoly->coeffErr);342 psFree(myPoly->mask);343 }344 345 static void polynomial2DFree(psPolynomial2D* myPoly)346 {347 psS32 x = 0;348 349 for (x = 0; x < myPoly->nX; x++) {350 psFree(myPoly->coeff[x]);351 psFree(myPoly->coeffErr[x]);352 psFree(myPoly->mask[x]);353 }354 psFree(myPoly->coeff);355 psFree(myPoly->coeffErr);356 psFree(myPoly->mask);357 }358 359 static void polynomial3DFree(psPolynomial3D* myPoly)360 {361 psS32 x = 0;362 psS32 y = 0;363 364 for (x = 0; x < myPoly->nX; x++) {365 for (y = 0; y < myPoly->nY; y++) {366 psFree(myPoly->coeff[x][y]);367 psFree(myPoly->coeffErr[x][y]);368 psFree(myPoly->mask[x][y]);369 }370 psFree(myPoly->coeff[x]);371 psFree(myPoly->coeffErr[x]);372 psFree(myPoly->mask[x]);373 }374 375 psFree(myPoly->coeff);376 psFree(myPoly->coeffErr);377 psFree(myPoly->mask);378 }379 380 static void polynomial4DFree(psPolynomial4D* myPoly)381 {382 psS32 w = 0;383 psS32 x = 0;384 psS32 y = 0;385 386 for (w = 0; w < myPoly->nW; w++) {387 for (x = 0; x < myPoly->nX; x++) {388 for (y = 0; y < myPoly->nY; y++) {389 psFree(myPoly->coeff[w][x][y]);390 psFree(myPoly->coeffErr[w][x][y]);391 psFree(myPoly->mask[w][x][y]);392 }393 psFree(myPoly->coeff[w][x]);394 psFree(myPoly->coeffErr[w][x]);395 psFree(myPoly->mask[w][x]);396 }397 psFree(myPoly->coeff[w]);398 psFree(myPoly->coeffErr[w]);399 psFree(myPoly->mask[w]);400 }401 402 psFree(myPoly->coeff);403 psFree(myPoly->coeffErr);404 psFree(myPoly->mask);405 }406 407 /*****************************************************************************408 Polynomial coefficients will be accessed in [w][x][y][z] fashion.409 410 XXX: Should the "coeffErr[]" should be used as well?411 *****************************************************************************/412 float p_psOrdPolynomial1DEval(float x, const psPolynomial1D* myPoly)413 {414 psS32 loop_x = 0;415 float polySum = 0.0;416 float xSum = 1.0;417 418 psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 4,419 "---- Calling p_psOrdPolynomial1DEval(%f)\n", x);420 psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 4,421 "Polynomial order is %d\n", myPoly->n);422 for (loop_x = 0; loop_x < myPoly->n; loop_x++) {423 psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 4,424 "Polynomial coeff[%d] is %f\n", loop_x, myPoly->coeff[loop_x]);425 }426 427 for (loop_x = 0; loop_x < myPoly->n; loop_x++) {428 if (myPoly->mask[loop_x] == 0) {429 psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 10,430 "polysum+= sum*coeff [%f+= (%f * %f)\n", polySum, xSum, myPoly->coeff[loop_x]);431 polySum += xSum * myPoly->coeff[loop_x];432 xSum *= x;433 }434 }435 436 return(polySum);437 }438 439 // XXX: You can do this without having to psAlloc() vector d.440 // XXX: How does the mask vector effect Crenshaw's formula?441 float p_psChebPolynomial1DEval(float x, const psPolynomial1D* myPoly)442 {443 psVector *d;444 psS32 n;445 psS32 i;446 float tmp;447 448 n = myPoly->n;449 d = psVectorAlloc(n, PS_TYPE_F32);450 d->data.F32[n-1] = myPoly->coeff[n-1];451 d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]) + myPoly->coeff[n-2];452 for (i=n-3;i>=1;i--) {453 d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -454 (d->data.F32[i+2]) +455 (myPoly->coeff[i]);456 }457 458 tmp = (x * d->data.F32[1]) -459 (d->data.F32[2]) +460 (0.5 * myPoly->coeff[0]);461 462 psFree(d);463 return(tmp);464 /*465 466 psS32 n;467 psS32 i;468 float tmp;469 psPolynomial1D **chebPolys = NULL;470 471 n = myPoly->n;472 chebPolys = CreateChebyshevPolys(n);473 474 tmp = 0.0;475 for (i=0;i<myPoly->n;i++) {476 tmp+= (myPoly->coeff[i] * psPolynomial1DEval(x, chebPolys[i]));477 // printf("HMMM: psPolynomial1DEval(%f, chebPolys[%d]) is %f\n", x, i, psPolynomial1DEval(x, chebPolys[i]));478 }479 tmp-= (myPoly->coeff[0]/2.0);480 481 482 return(tmp);483 */484 }485 486 1156 float psPolynomial1DEval(float x, const psPolynomial1D* myPoly) 487 1157 { … … 489 1159 490 1160 if (myPoly->type == PS_POLYNOMIAL_ORD) { 491 return( p_psOrdPolynomial1DEval(x, myPoly));1161 return(ordPolynomial1DEval(x, myPoly)); 492 1162 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 493 return( p_psChebPolynomial1DEval(x, myPoly));1163 return(chebPolynomial1DEval(x, myPoly)); 494 1164 } else { 495 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1165 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1166 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1167 myPoly->type); 496 1168 } 497 1169 return(0.0); … … 520 1192 } 521 1193 522 523 float p_psOrdPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 1194 float psPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 524 1195 { 525 1196 PS_POLY_CHECK_NULL(myPoly, NAN); 526 1197 527 psS32 loop_x = 0;528 psS32 loop_y = 0;529 float polySum = 0.0;530 float xSum = 1.0;531 float ySum = 1.0;532 533 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {534 ySum = xSum;535 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {536 if (myPoly->mask[loop_x][loop_y] == 0) {537 polySum += ySum * myPoly->coeff[loop_x][loop_y];538 ySum *= y;539 }540 }541 xSum *= x;542 }543 544 return(polySum);545 }546 547 float p_psChebPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)548 {549 PS_POLY_CHECK_NULL(myPoly, NAN);550 551 psS32 loop_x = 0;552 psS32 loop_y = 0;553 psS32 i = 0;554 float polySum = 0.0;555 psPolynomial1D* *chebPolys = NULL;556 psS32 maxChebyPoly = 0;557 558 // Determine how many Chebyshev polynomials559 // are needed, then create them.560 maxChebyPoly = myPoly->nX;561 if (myPoly->nY > maxChebyPoly) {562 maxChebyPoly = myPoly->nY;563 }564 chebPolys = CreateChebyshevPolys(maxChebyPoly);565 566 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {567 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {568 if (myPoly->mask[loop_x][loop_y] == 0) {569 polySum += myPoly->coeff[loop_x][loop_y] *570 psPolynomial1DEval(x, chebPolys[loop_x]) *571 psPolynomial1DEval(y, chebPolys[loop_y]);572 }573 }574 }575 for (i=0;i<maxChebyPoly;i++) {576 psFree(chebPolys[i]);577 }578 psFree(chebPolys);579 return(polySum);580 }581 582 float psPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)583 {584 PS_POLY_CHECK_NULL(myPoly, NAN);585 586 1198 if (myPoly->type == PS_POLYNOMIAL_ORD) { 587 return( p_psOrdPolynomial2DEval(x, y, myPoly));1199 return(ordPolynomial2DEval(x, y, myPoly)); 588 1200 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 589 return( p_psChebPolynomial2DEval(x, y, myPoly));1201 return(chebPolynomial2DEval(x, y, myPoly)); 590 1202 } else { 591 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1203 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1204 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1205 myPoly->type); 592 1206 } 593 1207 return(0.0); 594 1208 } 595 596 1209 597 1210 psVector *psPolynomial2DEvalVector(const psVector *x, … … 632 1245 } 633 1246 634 635 636 float p_psOrdPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly)637 {638 psS32 loop_x = 0;639 psS32 loop_y = 0;640 psS32 loop_z = 0;641 float polySum = 0.0;642 float xSum = 1.0;643 float ySum = 1.0;644 float zSum = 1.0;645 646 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {647 ySum = xSum;648 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {649 zSum = ySum;650 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {651 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {652 polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z];653 zSum *= z;654 }655 }656 ySum *= y;657 }658 xSum *= x;659 }660 661 return(polySum);662 }663 664 float p_psChebPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly)665 {666 psS32 loop_x = 0;667 psS32 loop_y = 0;668 psS32 loop_z = 0;669 psS32 i = 0;670 float polySum = 0.0;671 psPolynomial1D* *chebPolys = NULL;672 psS32 maxChebyPoly = 0;673 674 // Determine how many Chebyshev polynomials675 // are needed, then create them.676 maxChebyPoly = myPoly->nX;677 if (myPoly->nY > maxChebyPoly) {678 maxChebyPoly = myPoly->nY;679 }680 if (myPoly->nZ > maxChebyPoly) {681 maxChebyPoly = myPoly->nZ;682 }683 chebPolys = CreateChebyshevPolys(maxChebyPoly);684 685 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {686 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {687 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {688 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {689 polySum += myPoly->coeff[loop_x][loop_y][loop_z] *690 psPolynomial1DEval(x, chebPolys[loop_x]) *691 psPolynomial1DEval(y, chebPolys[loop_y]) *692 psPolynomial1DEval(z, chebPolys[loop_z]);693 }694 }695 }696 }697 698 for (i=0;i<maxChebyPoly;i++) {699 psFree(chebPolys[i]);700 }701 psFree(chebPolys);702 return(polySum);703 }704 705 1247 float psPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly) 706 1248 { … … 708 1250 709 1251 if (myPoly->type == PS_POLYNOMIAL_ORD) { 710 return( p_psOrdPolynomial3DEval(x, y, z, myPoly));1252 return(ordPolynomial3DEval(x, y, z, myPoly)); 711 1253 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 712 return( p_psChebPolynomial3DEval(x, y, z, myPoly));1254 return(chebPolynomial3DEval(x, y, z, myPoly)); 713 1255 } else { 714 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1256 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1257 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1258 myPoly->type); 715 1259 } 716 1260 return(0.0); … … 765 1309 } 766 1310 767 768 769 770 771 772 float p_psOrdPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly)773 {774 psS32 loop_w = 0;775 psS32 loop_x = 0;776 psS32 loop_y = 0;777 psS32 loop_z = 0;778 float polySum = 0.0;779 float wSum = 1.0;780 float xSum = 1.0;781 float ySum = 1.0;782 float zSum = 1.0;783 784 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {785 xSum = wSum;786 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {787 ySum = xSum;788 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {789 zSum = ySum;790 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {791 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {792 polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z];793 zSum *= z;794 }795 }796 ySum *= y;797 }798 xSum *= x;799 }800 wSum *= w;801 }802 803 return(polySum);804 }805 806 float p_psChebPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly)807 {808 psS32 loop_w = 0;809 psS32 loop_x = 0;810 psS32 loop_y = 0;811 psS32 loop_z = 0;812 psS32 i = 0;813 float polySum = 0.0;814 psPolynomial1D* *chebPolys = NULL;815 psS32 maxChebyPoly = 0;816 817 // Determine how many Chebyshev polynomials818 // are needed, then create them.819 maxChebyPoly = myPoly->nW;820 if (myPoly->nX > maxChebyPoly) {821 maxChebyPoly = myPoly->nX;822 }823 if (myPoly->nY > maxChebyPoly) {824 maxChebyPoly = myPoly->nY;825 }826 if (myPoly->nZ > maxChebyPoly) {827 maxChebyPoly = myPoly->nZ;828 }829 chebPolys = CreateChebyshevPolys(maxChebyPoly);830 831 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {832 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {833 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {834 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {835 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {836 polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] *837 psPolynomial1DEval(w, chebPolys[loop_w]) *838 psPolynomial1DEval(x, chebPolys[loop_x]) *839 psPolynomial1DEval(y, chebPolys[loop_y]) *840 psPolynomial1DEval(z, chebPolys[loop_z]);841 }842 }843 }844 }845 }846 847 for (i=0;i<maxChebyPoly;i++) {848 psFree(chebPolys[i]);849 }850 psFree(chebPolys);851 return(polySum);852 }853 854 1311 float psPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly) 855 1312 { … … 857 1314 858 1315 if (myPoly->type == PS_POLYNOMIAL_ORD) { 859 return( p_psOrdPolynomial4DEval(w,x,y,z, myPoly));1316 return(ordPolynomial4DEval(w,x,y,z, myPoly)); 860 1317 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 861 return( p_psChebPolynomial4DEval(w,x,y,z, myPoly));1318 return(chebPolynomial4DEval(w,x,y,z, myPoly)); 862 1319 } else { 863 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1320 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1321 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1322 myPoly->type); 864 1323 } 865 1324 return(0.0); … … 924 1383 return(tmp); 925 1384 } 926 927 928 929 1385 930 1386 … … 1092 1548 } 1093 1549 1094 static void dPolynomial1DFree(psDPolynomial1D* myPoly)1095 {1096 psFree(myPoly->coeff);1097 psFree(myPoly->coeffErr);1098 psFree(myPoly->mask);1099 }1100 1101 static void dPolynomial2DFree(psDPolynomial2D* myPoly)1102 {1103 psS32 x = 0;1104 1105 for (x = 0; x < myPoly->nX; x++) {1106 psFree(myPoly->coeff[x]);1107 psFree(myPoly->coeffErr[x]);1108 psFree(myPoly->mask[x]);1109 }1110 psFree(myPoly->coeff);1111 psFree(myPoly->coeffErr);1112 psFree(myPoly->mask);1113 }1114 1115 static void dPolynomial3DFree(psDPolynomial3D* myPoly)1116 {1117 psS32 x = 0;1118 psS32 y = 0;1119 1120 for (x = 0; x < myPoly->nX; x++) {1121 for (y = 0; y < myPoly->nY; y++) {1122 psFree(myPoly->coeff[x][y]);1123 psFree(myPoly->coeffErr[x][y]);1124 psFree(myPoly->mask[x][y]);1125 }1126 psFree(myPoly->coeff[x]);1127 psFree(myPoly->coeffErr[x]);1128 psFree(myPoly->mask[x]);1129 }1130 1131 psFree(myPoly->coeff);1132 psFree(myPoly->coeffErr);1133 psFree(myPoly->mask);1134 }1135 1136 static void dPolynomial4DFree(psDPolynomial4D* myPoly)1137 {1138 psS32 w = 0;1139 psS32 x = 0;1140 psS32 y = 0;1141 1142 for (w = 0; w < myPoly->nW; w++) {1143 for (x = 0; x < myPoly->nX; x++) {1144 for (y = 0; y < myPoly->nY; y++) {1145 psFree(myPoly->coeff[w][x][y]);1146 psFree(myPoly->coeffErr[w][x][y]);1147 psFree(myPoly->mask[w][x][y]);1148 }1149 psFree(myPoly->coeff[w][x]);1150 psFree(myPoly->coeffErr[w][x]);1151 psFree(myPoly->mask[w][x]);1152 }1153 psFree(myPoly->coeff[w]);1154 psFree(myPoly->coeffErr[w]);1155 psFree(myPoly->mask[w]);1156 }1157 1158 psFree(myPoly->coeff);1159 psFree(myPoly->coeffErr);1160 psFree(myPoly->mask);1161 }1162 1163 /*****************************************************************************1164 Polynomial coefficients will be accessed in [w][x][y][z] fashion.1165 *****************************************************************************/1166 double p_psDOrdPolynomial1DEval(double x, const psDPolynomial1D* myPoly)1167 {1168 psS32 loop_x = 0;1169 double polySum = 0.0;1170 double xSum = 1.0;1171 1172 for (loop_x = 0; loop_x < myPoly->n; loop_x++) {1173 if (myPoly->mask[loop_x] == 0) {1174 polySum += xSum * myPoly->coeff[loop_x];1175 xSum *= x;1176 }1177 }1178 1179 return(polySum);1180 }1181 1182 // XXX: You can do this without having to psAlloc() vector d.1183 // XXX: How does the mask vector effect Crenshaw's formula?1184 double p_psDChebPolynomial1DEval(double x, const psDPolynomial1D* myPoly)1185 {1186 psVector *d;1187 psS32 n;1188 psS32 i;1189 double tmp;1190 1191 n = myPoly->n;1192 d = psVectorAlloc(n, PS_TYPE_F64);1193 d->data.F64[n-1] = myPoly->coeff[n-1];1194 d->data.F64[n-2] = (2.0 * x * d->data.F64[n-1]) + myPoly->coeff[n-2];1195 for (i=n-3;i>=1;i--) {1196 d->data.F64[i] = (2.0 * x * d->data.F64[i+1]) -1197 (d->data.F64[i+2]) +1198 (myPoly->coeff[i]);1199 }1200 1201 tmp = (x * d->data.F64[1]) -1202 (d->data.F64[2]) +1203 (0.5 * myPoly->coeff[0]);1204 1205 psFree(d);1206 return(tmp);1207 }1208 1550 1209 1551 double psDPolynomial1DEval(double x, const psDPolynomial1D* myPoly) … … 1212 1554 1213 1555 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1214 return( p_psDOrdPolynomial1DEval(x, myPoly));1556 return(dOrdPolynomial1DEval(x, myPoly)); 1215 1557 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 1216 return( p_psDChebPolynomial1DEval(x, myPoly));1558 return(dChebPolynomial1DEval(x, myPoly)); 1217 1559 } else { 1218 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1560 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1561 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1562 myPoly->type); 1219 1563 } 1220 1564 return(0.0); … … 1244 1588 1245 1589 1246 1247 double p_psDOrdPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly)1248 {1249 psS32 loop_x = 0;1250 psS32 loop_y = 0;1251 double polySum = 0.0;1252 double xSum = 1.0;1253 double ySum = 1.0;1254 1255 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {1256 ySum = xSum;1257 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {1258 if (myPoly->mask[loop_x][loop_y] == 0) {1259 polySum += ySum * myPoly->coeff[loop_x][loop_y];1260 ySum *= y;1261 }1262 }1263 xSum *= x;1264 }1265 1266 return(polySum);1267 }1268 1269 double p_psDChebPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly)1270 {1271 psS32 loop_x = 0;1272 psS32 loop_y = 0;1273 psS32 i = 0;1274 double polySum = 0.0;1275 psPolynomial1D* *chebPolys = NULL;1276 psS32 maxChebyPoly = 0;1277 1278 // Determine how many Chebyshev polynomials1279 // are needed, then create them.1280 maxChebyPoly = myPoly->nX;1281 if (myPoly->nY > maxChebyPoly) {1282 maxChebyPoly = myPoly->nY;1283 }1284 chebPolys = CreateChebyshevPolys(maxChebyPoly);1285 1286 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {1287 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {1288 if (myPoly->mask[loop_x][loop_y] == 0) {1289 polySum += myPoly->coeff[loop_x][loop_y] *1290 psPolynomial1DEval(x, chebPolys[loop_x]) *1291 psPolynomial1DEval(y, chebPolys[loop_y]);1292 }1293 }1294 }1295 1296 for (i=0;i<maxChebyPoly;i++) {1297 psFree(chebPolys[i]);1298 }1299 psFree(chebPolys);1300 return(polySum);1301 }1302 1303 1590 double psDPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly) 1304 1591 { … … 1306 1593 1307 1594 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1308 return( p_psDOrdPolynomial2DEval(x, y, myPoly));1595 return(dOrdPolynomial2DEval(x, y, myPoly)); 1309 1596 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 1310 return( p_psDChebPolynomial2DEval(x, y, myPoly));1597 return(dChebPolynomial2DEval(x, y, myPoly)); 1311 1598 } else { 1312 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1599 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1600 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1601 myPoly->type); 1313 1602 } 1314 1603 return(0.0); … … 1353 1642 1354 1643 1355 1356 double p_psDOrdPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly)1357 {1358 psS32 loop_x = 0;1359 psS32 loop_y = 0;1360 psS32 loop_z = 0;1361 double polySum = 0.0;1362 double xSum = 1.0;1363 double ySum = 1.0;1364 double zSum = 1.0;1365 1366 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {1367 ySum = xSum;1368 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {1369 zSum = ySum;1370 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {1371 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {1372 polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z];1373 zSum *= z;1374 }1375 }1376 ySum *= y;1377 }1378 xSum *= x;1379 }1380 1381 return(polySum);1382 }1383 1384 double p_psDChebPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly)1385 {1386 psS32 loop_x = 0;1387 psS32 loop_y = 0;1388 psS32 loop_z = 0;1389 psS32 i = 0;1390 double polySum = 0.0;1391 psPolynomial1D* *chebPolys = NULL;1392 psS32 maxChebyPoly = 0;1393 1394 // Determine how many Chebyshev polynomials1395 // are needed, then create them.1396 maxChebyPoly = myPoly->nX;1397 if (myPoly->nY > maxChebyPoly) {1398 maxChebyPoly = myPoly->nY;1399 }1400 if (myPoly->nZ > maxChebyPoly) {1401 maxChebyPoly = myPoly->nZ;1402 }1403 chebPolys = CreateChebyshevPolys(maxChebyPoly);1404 1405 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {1406 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {1407 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {1408 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {1409 polySum += myPoly->coeff[loop_x][loop_y][loop_z] *1410 psPolynomial1DEval(x, chebPolys[loop_x]) *1411 psPolynomial1DEval(y, chebPolys[loop_y]) *1412 psPolynomial1DEval(z, chebPolys[loop_z]);1413 }1414 }1415 }1416 }1417 1418 for (i=0;i<maxChebyPoly;i++) {1419 psFree(chebPolys[i]);1420 }1421 psFree(chebPolys);1422 return(polySum);1423 }1424 1425 1644 double psDPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly) 1426 1645 { … … 1428 1647 1429 1648 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1430 return( p_psDOrdPolynomial3DEval(x, y, z, myPoly));1649 return(dOrdPolynomial3DEval(x, y, z, myPoly)); 1431 1650 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 1432 return( p_psDChebPolynomial3DEval(x, y, z, myPoly));1651 return(dChebPolynomial3DEval(x, y, z, myPoly)); 1433 1652 } else { 1434 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1653 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1654 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1655 myPoly->type); 1435 1656 } 1436 1657 return(0.0); … … 1485 1706 } 1486 1707 1487 1488 1489 1490 1491 1492 1493 1494 double p_psDOrdPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly)1495 {1496 psS32 loop_w = 0;1497 psS32 loop_x = 0;1498 psS32 loop_y = 0;1499 psS32 loop_z = 0;1500 double polySum = 0.0;1501 double wSum = 1.0;1502 double xSum = 1.0;1503 double ySum = 1.0;1504 double zSum = 1.0;1505 1506 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {1507 xSum = wSum;1508 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {1509 ySum = xSum;1510 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {1511 zSum = ySum;1512 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {1513 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {1514 polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z];1515 zSum *= z;1516 }1517 }1518 ySum *= y;1519 }1520 xSum *= x;1521 }1522 wSum *= w;1523 }1524 1525 return(polySum);1526 }1527 1528 double p_psDChebPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly)1529 {1530 psS32 loop_w = 0;1531 psS32 loop_x = 0;1532 psS32 loop_y = 0;1533 psS32 loop_z = 0;1534 psS32 i = 0;1535 double polySum = 0.0;1536 psPolynomial1D* *chebPolys = NULL;1537 psS32 maxChebyPoly = 0;1538 1539 // Determine how many Chebyshev polynomials1540 // are needed, then create them.1541 maxChebyPoly = myPoly->nW;1542 if (myPoly->nX > maxChebyPoly) {1543 maxChebyPoly = myPoly->nX;1544 }1545 if (myPoly->nY > maxChebyPoly) {1546 maxChebyPoly = myPoly->nY;1547 }1548 if (myPoly->nZ > maxChebyPoly) {1549 maxChebyPoly = myPoly->nZ;1550 }1551 chebPolys = CreateChebyshevPolys(maxChebyPoly);1552 1553 for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {1554 for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {1555 for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {1556 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {1557 if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {1558 polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] *1559 psPolynomial1DEval(w, chebPolys[loop_w]) *1560 psPolynomial1DEval(x, chebPolys[loop_x]) *1561 psPolynomial1DEval(y, chebPolys[loop_y]) *1562 psPolynomial1DEval(z, chebPolys[loop_z]);1563 }1564 }1565 }1566 }1567 }1568 1569 for (i=0;i<maxChebyPoly;i++) {1570 psFree(chebPolys[i]);1571 }1572 psFree(chebPolys);1573 return(polySum);1574 }1575 1576 1708 double psDPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly) 1577 1709 { … … 1579 1711 1580 1712 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1581 return( p_psDOrdPolynomial4DEval(w,x,y,z, myPoly));1713 return(dOrdPolynomial4DEval(w,x,y,z, myPoly)); 1582 1714 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 1583 return( p_psDChebPolynomial4DEval(w,x,y,z, myPoly));1715 return(dChebPolynomial4DEval(w,x,y,z, myPoly)); 1584 1716 } else { 1585 psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type); 1717 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1718 PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE, 1719 myPoly->type); 1586 1720 } 1587 1721 return(0.0); … … 1699 1833 (tmp->domains)[numSplines] = max; 1700 1834 1835 p_psMemSetDeallocator(tmp,(psFreeFcn)spline1DFree); 1701 1836 return(tmp); 1702 1837 } 1703 1838 1704 // XXX: Have Robert put the dealocator in the memory file.1705 psS32 p_psSpline1DFree(psSpline1D *tmpSpline)1706 {1707 psS32 i;1708 1709 if (tmpSpline == NULL) {1710 return(0);1711 }1712 1713 if (tmpSpline->spline != NULL) {1714 for (i=0;i<tmpSpline->n;i++) {1715 psFree((tmpSpline->spline)[i]);1716 }1717 psFree(tmpSpline->spline);1718 }1719 1720 if (tmpSpline->p_psDeriv2 != NULL) {1721 psFree(tmpSpline->p_psDeriv2);1722 }1723 psFree(tmpSpline->domains);1724 psFree(tmpSpline);1725 1726 return(0);1727 }1728 1839 1729 1840 /***************************************************************************** … … 1765 1876 1766 1877 /***************************************************************************** 1767 p_psVectorBinDisectF32(): This is a private function which takes as input a1878 vectorBinDisectF32(): This is a private function which takes as input a 1768 1879 vector of floating point data as well as a single floating point values. 1769 1880 The input vector values are assumed to be non-decreasing (v[i-1] <= v[j] for … … 1776 1887 XXX: name since we don't take psVectors as input. 1777 1888 *****************************************************************************/ 1778 psS32 p_psVectorBinDisectF32(float *bins,1779 psS32 numBins,1780 float x)1889 static psS32 vectorBinDisectF32(float *bins, 1890 psS32 numBins, 1891 float x) 1781 1892 { 1782 1893 psS32 min; … … 1784 1895 psS32 mid; 1785 1896 1786 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectF32", 4,1787 "---- Calling p_psVectorBinDisectF32(%f)\n", x);1897 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4, 1898 "---- Calling vectorBinDisectF32(%f)\n", x); 1788 1899 1789 1900 if (x < bins[0]) { 1790 1901 psLogMsg(__func__, PS_LOG_WARN, 1791 " p_psVectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",1902 "vectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).", 1792 1903 x, bins[0], bins[numBins-1]); 1793 1904 return(-2); … … 1796 1907 if (x > bins[numBins-1]) { 1797 1908 psLogMsg(__func__, PS_LOG_WARN, 1798 " p_psVectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",1909 "vectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).", 1799 1910 x, bins[0], bins[numBins-1]); 1800 1911 return(-1); … … 1806 1917 1807 1918 while (min != max) { 1808 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectF32", 4,1919 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4, 1809 1920 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1810 1921 min, mid, max, x, bins[mid]); 1811 1922 1812 1923 if (x == bins[mid]) { 1813 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectF32", 4,1814 "---- Exiting p_psVectorBinDisectF32(): bin %d\n", mid);1924 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4, 1925 "---- Exiting vectorBinDisectF32(): bin %d\n", mid); 1815 1926 return(mid); 1816 1927 } else if (x < bins[mid]) { … … 1822 1933 } 1823 1934 1824 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectF32", 4,1825 "---- Exiting p_psVectorBinDisectF32(): bin %d\n", min);1935 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4, 1936 "---- Exiting vectorBinDisectF32(): bin %d\n", min); 1826 1937 return(min); 1827 1938 } 1828 1939 1829 1940 /***************************************************************************** 1830 p_psVectorBinDisectS32(): integer version of above.1941 vectorBinDisectS32(): integer version of above. 1831 1942 *****************************************************************************/ 1832 psS32 p_psVectorBinDisectS32(psS32 *bins,1833 psS32 numBins,1834 psS32 x)1943 static psS32 vectorBinDisectS32(psS32 *bins, 1944 psS32 numBins, 1945 psS32 x) 1835 1946 { 1836 1947 psS32 min; … … 1838 1949 psS32 mid; 1839 1950 1840 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectS32", 4,1841 "---- Calling p_psVectorBinDisectS32(%f)\n", x);1951 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4, 1952 "---- Calling vectorBinDisectS32(%f)\n", x); 1842 1953 1843 1954 if ((x < bins[0]) || 1844 1955 (x > bins[numBins-1])) { 1845 1956 psLogMsg(__func__, PS_LOG_WARN, 1846 " p_psVectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).",1957 "vectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).", 1847 1958 x, bins[0], bins[numBins-1]); 1848 1959 return(-1); … … 1854 1965 1855 1966 while (min != max) { 1856 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectS32", 4,1967 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4, 1857 1968 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1858 1969 min, mid, max, x, bins[mid]); 1859 1970 1860 1971 if (x == bins[mid]) { 1861 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectS32", 4,1862 "---- Exiting p_psVectorBinDisectS32(): bin %d\n", min);1972 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4, 1973 "---- Exiting vectorBinDisectS32(): bin %d\n", min); 1863 1974 return(min); 1864 1975 } else if (x < bins[mid]) { … … 1870 1981 } 1871 1982 1872 psTrace(".psLib.dataManip.psFunctions. p_psVectorBinDisectS32", 4,1873 "---- Exiting p_psVectorBinDisectS32(): bin %d\n", min);1983 psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4, 1984 "---- Exiting vectorBinDisectS32(): bin %d\n", min); 1874 1985 return(min); 1875 1986 } … … 1884 1995 1885 1996 if (x->type.type == PS_TYPE_S32) { 1886 return( p_psVectorBinDisectS32(bins->data.S32, bins->n, x->data.S32));1997 return(vectorBinDisectS32(bins->data.S32, bins->n, x->data.S32)); 1887 1998 } else if (x->type.type == PS_TYPE_F32) { 1888 return( p_psVectorBinDisectF32(bins->data.F32, bins->n, x->data.F32));1999 return(vectorBinDisectF32(bins->data.F32, bins->n, x->data.F32)); 1889 2000 } else { 1890 psError(__func__, "Unallowable data type."); 2001 char* strType; 2002 PS_TYPE_NAME(strType,x->type.type); 2003 psError(PS_ERR_BAD_PARAMETER_TYPE, 2004 PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED, 2005 strType); 1891 2006 return(-2); 1892 2007 } 1893 2008 return(-1); 1894 }1895 1896 /*****************************************************************************1897 p_psInterpolate1D(): This routine will take as input n-element floating1898 point arrays domain and range, and the x value, assumed to lie with the1899 domain vector. It produces as output the (n-1)-order LaGrange interpolated1900 value of x.1901 1902 XXX: do we error check for non-distinct domain values?1903 *****************************************************************************/1904 float p_ps1DFullInterpolateF32(float *domain,1905 float *range,1906 psS32 n,1907 float x)1908 {1909 PS_INT_CHECK_NON_NEGATIVE(n, NAN);1910 PS_PTR_CHECK_NULL(domain, NAN);1911 PS_PTR_CHECK_NULL(range, NAN);1912 1913 psS32 i;1914 psS32 m;1915 static psVector *p = NULL;1916 p = psVectorRecycle(p, n, PS_TYPE_F32);1917 p_psMemSetPersistent(p, true);1918 p_psMemSetPersistent(p->data.F32, true);1919 /*1920 psVector *p = psVectorAlloc(n, PS_TYPE_F32);1921 float tmp;1922 */1923 1924 psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 4,1925 "---- p_ps1DFullInterpolateF32() begin (%d-order at x=%f) (%d data points)----\n", n-1, x, n);1926 1927 for (i=0;i<n;i++) {1928 psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 6,1929 "domain/range is (%f %f)\n", domain[i], range[i]);1930 }1931 1932 for (i=0;i<n;i++) {1933 p->data.F32[i] = range[i];1934 psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 6,1935 "p->data.F32[%d] is %f\n", i, p->data.F32[i]);1936 1937 }1938 1939 // From NR, during each iteration of the m loop, we are computing the1940 // p_{i ... i+m} terms.1941 for (m=1;m<n;m++) {1942 for (i=0;i<n-m;i++) {1943 // From NR: we are computing P_{i ... i+m}1944 p->data.F32[i] = (((x-domain[i+m]) * p->data.F32[i]) +1945 ((domain[i]-x) * p->data.F32[i+1])) /1946 (domain[i] - domain[i+m]);1947 //printf("((%f-%f * %f) + (%f-%f * %f)) / (%f - %f)\n", x, domain[i+m], p->data.F32[i], domain[i], x, p->data.F32[i+1], domain[i], domain[i+m]);1948 psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 6,1949 "p->data.F32[%d] is %f\n", i, p->data.F32[i]);1950 }1951 }1952 psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 4,1953 "---- p_ps1DFullInterpolateF32() end ----\n");1954 1955 /*1956 tmp = p->data.F32[0];1957 psFree(p);1958 return(tmp);1959 */1960 return(p->data.F32[0]);1961 }1962 1963 1964 /*****************************************************************************1965 p_ps1DInterpolateF32(): this is the base 1-D flat memory routine to perform1966 LaGrange interpolation.1967 *****************************************************************************/1968 float p_ps1DInterpolateF32(float *domain,1969 float *range,1970 psS32 n,1971 psS32 order,1972 float x)1973 {1974 psS32 binNum;1975 psS32 numIntPoints = order+1;1976 psS32 origin;1977 1978 psTrace(".psLib.dataManip.psFunctions.p_ps1DInterpolateF32", 4,1979 "---- p_ps1DInterpolateF32() begin ----\n");1980 1981 binNum = p_psVectorBinDisectF32(domain, n, x);1982 1983 if (0 == numIntPoints%2) {1984 origin = binNum - ((numIntPoints/2) - 1);1985 } else {1986 origin = binNum - (numIntPoints/2);1987 if ((x-domain[binNum]) > (domain[binNum+1]-x)) {1988 // x is closer to binNum+1.1989 origin = 1 + (binNum - (numIntPoints/2));1990 }1991 }1992 if (origin < 0) {1993 origin = 0;1994 }1995 if ((origin + numIntPoints) > n) {1996 origin = n - numIntPoints;1997 }1998 1999 psTrace(".psLib.dataManip.psFunctions.p_ps1DInterpolateF32", 4,2000 "---- p_ps1DInterpolateF32() end ----\n");2001 return(p_ps1DFullInterpolateF32(&domain[origin], &range[origin], order+1, x));2002 2009 } 2003 2010 … … 2035 2042 2036 2043 if (order > (domain->n - 1)) { 2037 psError(__func__, "not enough data points for %d-order interpolation.\n", order); 2044 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 2045 PS_ERRORTEXT_psFunctions_NOT_ENOUGH_DATAPOINTS, 2046 order); 2038 2047 return(NULL); 2039 2048 } … … 2042 2051 psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4, 2043 2052 "---- p_psVectorInterpolate() end ----\n"); 2044 return(psScalarAlloc( p_ps1DInterpolateF32(domain->data.F32,2045 range->data.F32,2046 domain->n,2047 order,2048 x->data.F32), PS_TYPE_F32));2053 return(psScalarAlloc(interpolate1DF32(domain->data.F32, 2054 range->data.F32, 2055 domain->n, 2056 order, 2057 x->data.F32), PS_TYPE_F32)); 2049 2058 } else if (x->type.type == PS_TYPE_F64) { 2050 2059 // XXX: use recycled vectors here. … … 2053 2062 2054 2063 psScalar *tmpScalar = psScalarAlloc((double) 2055 p_ps1DInterpolateF32(domain32->data.F32,2056 range32->data.F32,2057 domain32->n,2058 order,2059 (float) x->data.F64), PS_TYPE_F64);2064 interpolate1DF32(domain32->data.F32, 2065 range32->data.F32, 2066 domain32->n, 2067 order, 2068 (float) x->data.F64), PS_TYPE_F64); 2060 2069 psFree(range32); 2061 2070 psFree(domain32); … … 2067 2076 2068 2077 } else { 2069 // XXX psError: type not supported 2070 psError(__func__, "type %d not supported\n", x->type.type); 2078 char* strType; 2079 PS_TYPE_NAME(strType,x->type.type); 2080 psError(PS_ERR_BAD_PARAMETER_TYPE, 2081 PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED, 2082 strType); 2071 2083 } 2072 2084 … … 2084 2096 and an independent x value. Each determines which spline that x corresponds 2085 2097 to by doing a bracket disection on the domains of the spline data structure 2086 ( p_psVectorBinDisectF32()). Then it evaluates the spline at that x location2098 (vectorBinDisectF32()). Then it evaluates the spline at that x location 2087 2099 by a call to the 1D polynomial functions. 2088 2100 … … 2100 2112 2101 2113 n = spline->n; 2102 binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x);2114 binNum = vectorBinDisectF32(spline->domains, (spline->n)+1, x); 2103 2115 if (binNum < 0) { 2104 2116 psLogMsg(__func__, PS_LOG_WARN, … … 2139 2151 } 2140 2152 } else { 2141 psError(__func__, "Unknown data type.\n"); 2153 char* strType; 2154 PS_TYPE_NAME(strType,x->type.type); 2155 psError(PS_ERR_BAD_PARAMETER_TYPE, 2156 PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED, 2157 strType); 2142 2158 return(NULL); 2143 2159 } -
trunk/psLib/src/dataManip/psFunctions.h
r2269 r2273 12 12 * @author George Gusciora, MHPCC 13 13 * 14 * @version $Revision: 1.3 2$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-11-0 3 03:30:30$14 * @version $Revision: 1.33 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-11-04 01:04:59 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 398 398 float max); 399 399 400 psS32 p_psSpline1DFree(psSpline1D *tmpSpline);401 402 400 psSpline1D *psSpline1DAllocGeneric(const psVector *bounds, 403 401 psS32 order); -
trunk/psLib/src/dataManip/psMatrix.c
r2214 r2273 20 20 * @author Ross Harman, MHPCC 21 21 * 22 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $23 * @date $Date: 2004-1 0-27 20:20:11$22 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2004-11-04 01:04:59 $ 24 24 * 25 25 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 40 40 #include "psVector.h" 41 41 #include "psMatrix.h" 42 43 /** Preprocessor macro to generate error a NULL image */ 44 #define PS_VECTOR_CHECK_NULL(NAME, RETURN) \ 45 if (NAME == NULL || NAME->data.V == NULL) { \ 46 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \ 47 return RETURN; \ 48 } 49 50 /** Preprocessor macro to create vector based on another */ 51 #define PS_CHECK_ALLOC_VECTOR(NAME, SIZE, PS_TYPE) \ 52 if(NAME == NULL) { \ 53 NAME = psVectorAlloc(SIZE, PS_TYPE); \ 54 } 55 56 /** Preprocessor macro to generate error for zero length vector */ 57 #define PS_CHECK_SIZE_VECTOR(NAME, RETURN) \ 58 if (NAME->n < 1) { \ 59 psError(__func__,"Invalid operation: %s has zero n value.", #NAME); \ 60 return RETURN; \ 61 } 62 63 /** Preprocessor macro to generate error a NULL image */ 64 #define PS_IMAGE_CHECK_NULL(NAME, RETURN) \ 65 if (NAME == NULL || NAME->data.V == NULL) { \ 66 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \ 67 return RETURN; \ 68 } 69 70 /** Preprocessor macro to create image based on another */ 71 #define PS_CHECK_ALLOC_IMAGE(NAME, NCOLS, NROWS, PS_TYPE) \ 72 if(NAME == NULL) { \ 73 NAME = psImageAlloc(NCOLS, NROWS, PS_TYPE); \ 74 } 75 76 /** Preprocessor macro to generate error for zero length rows or columns */ 77 #define PS_CHECK_SIZE_IMAGE(NAME, RETURN) \ 78 if (NAME->numCols < 1 || NAME->numRows < 1) { \ 79 psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME, \ 80 NAME->numCols, NAME->numRows); \ 81 return RETURN; \ 82 } 42 #include "psConstants.h" 43 44 83 45 84 46 /** Preprocessor macro to generate error for image dimensionality not set to PS_DIMEN_IMAGE */ 85 47 #define PS_CHECK_DIMEN_AND_TYPE(NAME, PS_DIMEN, RETURN) \ 86 48 if (NAME->type.dimen != PS_DIMEN) { \ 87 psError(__func__,"Invalid operation: %s incorrect dimensionality %d.", #NAME, PS_DIMEN); \ 49 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 50 "Invalid operation. %s has incorrect dimensionality %d.", #NAME, PS_DIMEN); \ 88 51 return RETURN; \ 89 52 } else if(NAME->type.type != PS_TYPE_F64) { \ 90 psError(__func__, "Invalid operation: %s not PS_TYPE_F64.", #NAME); \ 53 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 54 "Invalid operation. %s not PS_TYPE_F64.", #NAME); \ 91 55 return RETURN; \ 92 56 } … … 95 59 #define PS_CHECK_POINTERS(NAME1, NAME2, RETURN) \ 96 60 if (NAME1 == NAME2) { \ 97 psError(__func__,"Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2); \ 61 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 62 "Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2); \ 98 63 return RETURN; \ 99 64 } … … 102 67 #define PS_CHECK_SQUARE(NAME, RETURN) \ 103 68 if (NAME->numCols != NAME->numRows) { \ 104 psError(__func__,"Invalid operation: %s not square array.", #NAME); \ 69 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 70 "Invalid operation: %s not square array.", #NAME); \ 105 71 return RETURN; \ 106 72 } … … 126 92 gsl_permutation perm; 127 93 94 #define psMatrixLUD_EXIT { \ 95 psFree(outImage); \ 96 return NULL; \ 97 } 98 128 99 // Error checks 129 100 PS_CHECK_POINTERS(inImage, outImage, outImage); 130 PS_IMAGE_CHECK_NULL(inImage, outImage);131 101 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 132 PS_CHECK_SIZE_IMAGE(inImage, outImage); 133 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 134 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 135 PS_CHECK_SIZE_IMAGE(outImage, outImage); 136 PS_CHECK_ALLOC_VECTOR(outPerm, inImage->numRows, inImage->type.type); 137 PS_VECTOR_CHECK_NULL(outPerm, outImage); 102 103 PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixLUD_EXIT); 104 PS_VECTOR_CHECK_NULL_GENERAL(outPerm, psMatrixLUD_EXIT); 105 138 106 PS_CHECK_DIMEN_AND_TYPE(outPerm, PS_DIMEN_VECTOR, outImage); 107 108 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 109 psVectorRecycle(outPerm, inImage->numRows, inImage->type.type); 139 110 140 111 // Initialize data … … 179 150 PS_IMAGE_CHECK_NULL(inImage, outVector); 180 151 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector); 181 PS_CHECK_SIZE_IMAGE(inImage, outVector); 182 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type); 152 PS_IMAGE_CHECK_EMPTY(inImage, outVector); 183 153 PS_VECTOR_CHECK_NULL(outVector, outVector); 184 154 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector); … … 188 158 PS_CHECK_DIMEN_AND_TYPE(inPerm, PS_DIMEN_VECTOR, outVector); 189 159 160 psVectorRecycle(outVector, inImage->numRows, inImage->type.type); 161 162 190 163 // Initialize data 191 164 numRows = inImage->numRows; … … 226 199 227 200 // Error checks 228 if (det == NULL) { 229 psError(__func__, "Invalid operation: determinant argument is NULL."); 230 return outImage; 231 } 201 PS_PTR_CHECK_NULL(det, outImage); 232 202 PS_CHECK_POINTERS(inImage, outImage, outImage); 233 203 PS_IMAGE_CHECK_NULL(inImage, outImage); 234 204 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 235 PS_CHECK_SIZE_IMAGE(inImage, outImage); 236 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 237 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 238 PS_CHECK_SIZE_IMAGE(outImage, outImage); 205 PS_IMAGE_CHECK_EMPTY(inImage, outImage); 206 207 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 239 208 240 209 // Initialize data … … 282 251 PS_IMAGE_CHECK_NULL(inImage, NULL); 283 252 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL); 284 PS_ CHECK_SIZE_IMAGE(inImage, NULL);253 PS_IMAGE_CHECK_EMPTY(inImage, NULL); 285 254 286 255 // Initialize data … … 325 294 PS_IMAGE_CHECK_NULL(inImage1, outImage); 326 295 PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage); 327 PS_ CHECK_SIZE_IMAGE(inImage1, outImage);296 PS_IMAGE_CHECK_EMPTY(inImage1, outImage); 328 297 PS_IMAGE_CHECK_NULL(inImage2, outImage); 329 298 PS_CHECK_DIMEN_AND_TYPE(inImage2, PS_DIMEN_IMAGE, outImage); 330 PS_CHECK_SIZE_IMAGE(inImage2, outImage); 331 PS_CHECK_ALLOC_IMAGE(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type); 299 PS_IMAGE_CHECK_EMPTY(inImage2, outImage); 332 300 PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage); 333 PS_CHECK_SIZE_IMAGE(outImage, outImage); 301 302 psImageRecycle(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type); 334 303 335 304 // Initialize data … … 364 333 PS_IMAGE_CHECK_NULL(inImage, outImage); 365 334 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 366 PS_CHECK_SIZE_IMAGE(inImage, outImage); 367 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 368 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 369 PS_CHECK_SIZE_IMAGE(outImage, outImage); 335 PS_IMAGE_CHECK_EMPTY(inImage, outImage); 336 337 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 370 338 371 339 // Initialize data … … 403 371 PS_IMAGE_CHECK_NULL(inImage, outImage); 404 372 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 405 PS_CHECK_SIZE_IMAGE(inImage, outImage); 406 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 407 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 408 PS_CHECK_SIZE_IMAGE(outImage, outImage); 373 PS_IMAGE_CHECK_EMPTY(inImage, outImage); 374 375 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 409 376 410 377 // Initialize data … … 438 405 psS32 size = 0; 439 406 440 // Error checks 441 PS_IMAGE_CHECK_NULL(inImage, outVector); 407 #define psMatrixToVector_EXIT { \ 408 psFree(outVector); \ 409 return NULL; \ 410 } 411 412 // Error checks 413 PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixToVector_EXIT); 442 414 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector); 443 PS_ CHECK_SIZE_IMAGE(inImage, outVector);415 PS_IMAGE_CHECK_EMPTY_GENERAL(inImage, psMatrixToVector_EXIT); 444 416 445 417 if (inImage->numRows == 1) { 446 418 // Create transposed row vector 447 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type);419 psVectorRecycle(outVector, inImage->numCols, inImage->type.type); 448 420 outVector->type.dimen = PS_DIMEN_TRANSV; 449 421 } else if (inImage->numCols == 1) { 450 422 // Create non-transposed column vector 451 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);423 psVectorRecycle(outVector, inImage->numRows, inImage->type.type); 452 424 } else { 453 psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows, 454 inImage->numCols); 425 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 426 "Image does not have dim with 1 col or 1 row: (%d x %d).", 427 inImage->numRows, inImage->numCols); 455 428 return outVector; 456 429 } … … 467 440 468 441 if (outVector->n != inImage->numRows) { 469 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n); 442 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 443 "Image and vector sizes differ: (%d vs %d).", 444 inImage->numRows, outVector->n); 470 445 return outVector; 471 446 } … … 481 456 482 457 if (outVector->n != inImage->numCols) { 483 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n); 458 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 459 "Image and vector sizes differ: (%d vs %d).", 460 inImage->numCols, outVector->n); 484 461 return outVector; 485 462 } … … 502 479 if (inVector->type.dimen == PS_DIMEN_VECTOR) { 503 480 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage); 504 PS_ CHECK_SIZE_VECTOR(inVector, outImage);505 PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64)481 PS_VECTOR_CHECK_EMPTY(inVector, outImage); 482 psImageRecycle(outImage, 1, inVector->n, PS_TYPE_F64); 506 483 // More checks for PS_DIMEN_VECTOR 507 484 if (outImage->numCols > 1) { 508 psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols); 485 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 486 "Image has more than 1 column: numCols = %d.", 487 outImage->numCols); 509 488 return outImage; 510 489 } else if (outImage->numRows != inVector->n) { 511 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n); 490 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 491 "Image and vector sizes differ: (%d vs %d).", 492 outImage->numRows, inVector->n); 512 493 return outImage; 513 494 } … … 517 498 } else if (inVector->type.dimen == PS_DIMEN_TRANSV) { 518 499 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage); 519 PS_ CHECK_SIZE_VECTOR(inVector, outImage);520 PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64)500 PS_VECTOR_CHECK_EMPTY(inVector, outImage); 501 psImageRecycle(outImage, inVector->n, 1, PS_TYPE_F64); 521 502 // More checks for PS_DIMEN_TRANSV 522 503 if (outImage->numRows > 1) { 523 psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows); 504 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 505 "Image has more than 1 row: numRows = %d.", 506 outImage->numRows); 524 507 return outImage; 525 508 } else if (outImage->numCols != inVector->n) { 526 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n); 509 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 510 "Image and vector sizes differ: (%d vs %d).", 511 outImage->numCols, inVector->n); 527 512 return outImage; 528 513 } -
trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
r2204 r2273 29 29 * @author Ross Harman, MHPCC 30 30 * 31 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $32 * @date $Date: 2004-1 0-27 00:57:31$31 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 32 * @date $Date: 2004-11-04 01:04:59 $ 33 33 * 34 34 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 48 48 #include "psScalar.h" 49 49 #include "psLogMsg.h" 50 #include "psConstants.h" 51 #include "psDataManipErrors.h" 50 52 51 53 /***************************************************************************** … … 58 60 // Conversion for radians to degrees 59 61 #define R2D 57.29577950924861 /* 180.0/PI */ 60 61 /* IEEE Standards on floating-point makes this function pointless, really.62 // Division with NAN checking63 static complex double psNanDiv(complex double a, complex double b)64 {65 complex double out = 0 + 0i;66 67 out = a / b;68 if (isnan(creal(out)) || isnan(cimag(out))) {69 psError(__func__, ": Divide by zero");70 }71 72 return out;73 }74 */75 62 76 63 // Binary SCALAR_XXXX operations … … 142 129 #define VECTOR_VECTOR(OUT,IN1,OP,IN2,TYPE) \ 143 130 { \ 144 psS32 i = 0; \145 psS32 n1 = 0; \146 psS32 n2 = 0; \131 psS32 i = 0; \ 132 psS32 n1 = 0; \ 133 psS32 n2 = 0; \ 147 134 ps##TYPE *o = NULL; \ 148 135 ps##TYPE *i1 = NULL; \ … … 151 138 n2 = ((psVector* )IN2)->n; \ 152 139 if(n1 != n2) { \ 153 psError(__func__, ": Inconsistent element count: %d vs %d", n1, n2); \ 140 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 141 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 142 n1, n2); \ 154 143 if (OUT != IN1 && OUT != IN2) { \ 155 144 psFree(OUT); \ … … 167 156 #define VECTOR_IMAGE(OUT,IN1,OP,IN2,TYPE) \ 168 157 { \ 169 psS32 i = 0; \170 psS32 j = 0; \171 psS32 n1 = 0; \172 psS32 numRows2 = 0; \173 psS32 numCols2 = 0; \158 psS32 i = 0; \ 159 psS32 j = 0; \ 160 psS32 n1 = 0; \ 161 psS32 numRows2 = 0; \ 162 psS32 numCols2 = 0; \ 174 163 psDimen dim1 = 0; \ 175 164 ps##TYPE *o = NULL; \ … … 181 170 numCols2 = ((psImage* )IN2)->numCols; \ 182 171 \ 183 if(dim1 == PS_DIMEN_VECTOR) { /* Regular vectors */ \172 if(dim1 == PS_DIMEN_VECTOR) { /* Regular vectors */ \ 184 173 if(n1!=numRows2) { \ 185 psError(__func__, ": Inconsistent element count: %d vs %d", n1, numRows2); \ 174 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 175 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 176 n1, numRows2); \ 186 177 if (OUT != IN1 && OUT != IN2) { \ 187 178 psFree(OUT); \ … … 200 191 } else { /* Transposed vectors */ \ 201 192 if(n1!=numCols2) { \ 202 psError(__func__, ": Inconsistent element count: %d vs %d", n1, numCols2); \ 193 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 194 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 195 n1, numCols2); \ 203 196 if (OUT != IN1 && OUT != IN2) { \ 204 197 psFree(OUT); \ … … 256 249 numCols1 = ((psImage* )IN1)->numCols; \ 257 250 \ 258 if(dim2 == PS_DIMEN_VECTOR) { /* Regular vectors */ \251 if(dim2 == PS_DIMEN_VECTOR) { /* Regular vectors */ \ 259 252 if(n2!=numRows1) { \ 260 psError(__func__, ": Inconsistent element count: %d vs %d", n2, numRows1); \ 253 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 254 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 255 n2, numRows1); \ 261 256 if (OUT != IN1 && OUT != IN2) { \ 262 257 psFree(OUT); \ … … 275 270 } else { /* Transposed vectors */ \ 276 271 if(n2!=numCols1) { \ 277 psError(__func__, ": Inconsistent element count: %d vs %d", n2, numCols1); \ 272 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 273 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 274 n2, numCols1); \ 278 275 if (OUT != IN1) { \ 279 276 psFree(OUT); \ … … 309 306 numCols2 = ((psImage* )IN2)->numCols; \ 310 307 if(numRows1!=numRows2 || numCols1!=numCols2) { \ 311 psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRows1, \ 312 numRows2, numCols1, numCols2); \ 308 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 309 PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS, \ 310 numCols1, numRows1, numCols2, numRows2); \ 313 311 if (OUT != IN1 && OUT != IN2) { \ 314 312 psFree(OUT); \ … … 366 364 break; \ 367 365 default: \ 368 psError(__func__, ": Invalid PS_TYPE: %d", IN1->type); \ 366 /* char* strType; \ 367 PS_TYPE_NAME(strType,IN1->type); \ 368 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 369 PS_ERRORTEXT_psMatrix_TYPE_MISMATCH, \ 370 strType); */ \ 369 371 if (OUT != IN1 && OUT != IN2) { \ 370 372 psFree(OUT); \ … … 391 393 } else if(!strncmp(OP, "min", 3)) { \ 392 394 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ 393 psError(__func__, ": Minimum operation not supported for complex numbers"); \ 395 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 396 PS_ERRORTEXT_psMatrix_MIN_COMPLEX_SUPPORT); \ 394 397 if (OUT != IN1 && OUT != IN2) { \ 395 398 psFree(OUT); \ … … 401 404 } else if(!strncmp(OP, "max", 3)) { \ 402 405 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ 403 psError(__func__, ": Maximum operation not supported for complex numbers"); \ 406 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 407 PS_ERRORTEXT_psMatrix_MAX_COMPLEX_SUPPORT); \ 404 408 if (OUT != IN1 && OUT != IN2) { \ 405 409 psFree(OUT); \ … … 410 414 } \ 411 415 } else { \ 412 psError(__func__, ": Invalid operation: %s", OP); \ 416 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 417 PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED, \ 418 OP); \ 413 419 if (OUT != IN1 && OUT != IN2) { \ 414 420 psFree(OUT); \ … … 419 425 psPtr psBinaryOp(psPtr out, psPtr in1, char *op, psPtr in2) 420 426 { 421 psDimen dim1 = 0; 422 psDimen dim2 = 0; 423 psElemType elType1 = 0; 424 psElemType elType2 = 0; 425 psType* psType1 = NULL; 426 psType* psType2 = NULL; 427 428 psType1 = (psType* ) in1; 429 if (psType1 == NULL) { 430 psError(__func__, ": Line %d - Null in1 argument", __LINE__); 431 if (out != in1 && out != in2) { 432 psFree(out); 433 } 434 return NULL; 435 } 436 437 psType2 = (psType* ) in2; 438 if (psType2 == NULL) { 439 psError(__func__, ": Line %d - Null in2 argument", __LINE__); 440 if (out != in1 && out != in2) { 441 psFree(out); 442 } 443 return NULL; 444 } 445 446 if (op == NULL) { 447 psError(__func__, ": Line %d - Null op argument", __LINE__); 448 if (out != in1 && out != in2) { 449 psFree(out); 450 } 451 return NULL; 452 } 453 454 dim1 = psType1->dimen; 455 dim2 = psType2->dimen; 456 elType1 = psType1->type; 457 elType2 = psType2->type; 458 459 if (elType1 != elType2) { 460 psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d)", __LINE__, 461 elType1, elType2); 462 if (out != in1 && out != in2) { 463 psFree(out); 464 } 465 return NULL; 466 } 467 468 if (dim1 == PS_DIMEN_OTHER || dim2 == PS_DIMEN_OTHER) { 469 psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d)", __LINE__, 470 dim1, dim2); 471 if (out != in1 && out != in2) { 472 psFree(out); 473 } 474 return NULL; 475 } 427 428 psVector* input1 = (psVector* ) in1; 429 psVector* input2 = (psVector* ) in2; 430 431 #define psBinaryOp_EXIT { \ 432 if (out != in1 && out != in2) { \ 433 psFree(out); \ 434 } \ 435 return NULL; \ 436 } 437 438 PS_PTR_CHECK_NULL_GENERAL(input1, psBinaryOp_EXIT); 439 PS_PTR_CHECK_NULL_GENERAL(input2, psBinaryOp_EXIT); 440 PS_PTR_CHECK_NULL_GENERAL(op, psBinaryOp_EXIT); 441 442 PS_PTR_CHECK_TYPE_EQUAL_GENERAL(input1,input2, psBinaryOp_EXIT); 443 444 PS_PTR_CHECK_DIMEN_GENERAL(input1, PS_DIMEN_OTHER, psBinaryOp_EXIT); 445 PS_PTR_CHECK_DIMEN_GENERAL(input2, PS_DIMEN_OTHER, psBinaryOp_EXIT); 446 447 psType* psType1 = (psType*)in1; 448 psType* psType2 = (psType*)in2; 449 psDimen dim1 = psType1->dimen; 450 psDimen dim2 = psType2->dimen; 451 psElemType elType1 = psType1->type; 452 psElemType elType2 = psType2->type; 476 453 477 454 if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) { 478 455 if (((psVector* ) in1)->n == 0) { 479 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Vector contains zero elements");456 psLogMsg(__func__, PS_LOG_WARN, "Vector contains zero elements"); 480 457 } 481 458 } else if (dim1 == PS_DIMEN_IMAGE) { 482 459 if (((psImage* ) in1)->numCols == 0 || ((psImage* ) in1)->numRows == 0) { 483 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Image contains zero length row or cols");460 psLogMsg(__func__, PS_LOG_WARN, "Image contains zero length row or cols"); 484 461 } 485 462 } … … 487 464 if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 488 465 if (((psVector* ) in2)->n == 0) { 489 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Vector contains zero elements");466 psLogMsg(__func__, PS_LOG_WARN, "Vector contains zero elements"); 490 467 } 491 468 } else if (dim2 == PS_DIMEN_IMAGE) { 492 469 if (((psImage* ) in2)->numCols == 0 || ((psImage* ) in2)->numRows == 0) { 493 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Image contains zero length row or cols");470 psLogMsg(__func__, PS_LOG_WARN, "Image contains zero length row or cols"); 494 471 } 495 472 } … … 513 490 out = psVectorRecycle(out,((psVector*)in2)->n,elType1); 514 491 if (out == NULL) { 515 psError(__func__, "Couldn't create a proper output psVector."); 492 psError(PS_ERR_UNKNOWN, false, 493 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 516 494 return NULL; 517 495 } … … 520 498 out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows,elType1); 521 499 if (out == NULL) { 522 psError(__func__, "Couldn't create a proper output psImage."); 500 psError(PS_ERR_UNKNOWN, false, 501 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 523 502 return NULL; 524 503 } 525 504 BINARY_OP(SCALAR, IMAGE, out, psType1, op, psType2); // scalar op image 526 505 } else { 527 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 506 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 507 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 508 "in2",dim2); 509 psBinaryOp_EXIT; 528 510 } 529 511 } else if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) { … … 531 513 out = psVectorRecycle(out,((psVector*)in1)->n,elType1); 532 514 if (out == NULL) { 533 psError(__func__, "Couldn't create a proper output psVector."); 515 psError(PS_ERR_UNKNOWN, false, 516 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 534 517 return NULL; 535 518 } … … 538 521 out = psVectorRecycle(out,((psVector*)in2)->n,elType2); 539 522 if (out == NULL) { 540 psError(__func__, "Couldn't create a proper output psVector."); 523 psError(PS_ERR_UNKNOWN, false, 524 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 541 525 return NULL; 542 526 } … … 545 529 out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows, elType2); 546 530 if (out == NULL) { 547 psError(__func__, "Couldn't create a proper output psImage."); 531 psError(PS_ERR_UNKNOWN, false, 532 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 548 533 return NULL; 549 534 } 550 535 BINARY_OP(VECTOR, IMAGE, out, psType1, op, psType2); // vector op image 551 536 } else { 552 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 537 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 538 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 539 "in2",dim2); 540 psBinaryOp_EXIT; 553 541 } 554 542 } else if (dim1 == PS_DIMEN_IMAGE) { 555 543 out = psImageRecycle(out, ((psImage*)in1)->numCols, ((psImage*)in1)->numRows, elType1); 556 544 if (out == NULL) { 557 psError(__func__, "Couldn't create a proper output psImage."); 545 psError(PS_ERR_UNKNOWN, false, 546 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 558 547 return NULL; 559 548 } … … 565 554 BINARY_OP(IMAGE, IMAGE, out, psType1, op, psType2); // image op image 566 555 } else { 567 if (out != in1 && out != in2) { 568 psFree(out); 569 } 570 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 571 return NULL; 556 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 557 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 558 "in2",dim2); 559 psBinaryOp_EXIT; 572 560 } 573 561 } else { 574 if (out != in1 && out != in2) { 575 psFree(out); 576 } 577 psError(__func__, ": Line %d - Invalid dimensionality for in1 arg: %d", __LINE__, dim1); 578 return NULL; 562 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 563 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 564 "in1",dim1); 565 psBinaryOp_EXIT; 579 566 } 580 567 … … 605 592 #define VECTOR(OUT,IN,OP,TYPE) \ 606 593 { \ 607 psS32 i = 0; \608 psS32 nIn = 0; \609 psS32 nOut = 0; \594 psS32 i = 0; \ 595 psS32 nIn = 0; \ 596 psS32 nOut = 0; \ 610 597 ps##TYPE *o = NULL; \ 611 598 ps##TYPE *i1 = NULL; \ … … 613 600 nOut = ((psVector* )OUT)->n; \ 614 601 if(nIn != nOut) { \ 615 psError(__func__, ": Inconsistent element count: %d vs %d", nIn, nOut); \ 602 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 603 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 604 nIn, nOut); \ 616 605 if (OUT != IN) { \ 617 606 psFree(OUT); \ … … 629 618 #define IMAGE(OUT,IN,OP,TYPE) \ 630 619 { \ 631 psS32 i = 0; \632 psS32 j = 0; \633 psS32 numRowsIn = 0; \634 psS32 numColsIn = 0; \635 psS32 numRowsOut = 0; \636 psS32 numColsOut = 0; \620 psS32 i = 0; \ 621 psS32 j = 0; \ 622 psS32 numRowsIn = 0; \ 623 psS32 numColsIn = 0; \ 624 psS32 numRowsOut = 0; \ 625 psS32 numColsOut = 0; \ 637 626 ps##TYPE *o = NULL; \ 638 627 ps##TYPE *i1 = NULL; \ … … 642 631 numColsOut = ((psImage* )OUT)->numCols; \ 643 632 if(numRowsIn!=numRowsOut || numColsIn!=numColsOut) { \ 644 psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRowsIn, \ 645 numRowsOut, numColsIn, numColsOut); \ 633 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 634 PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS, \ 635 numColsIn, numRowsIn, numColsOut, numRowsOut); \ 646 636 if (OUT != IN) { \ 647 637 psFree(OUT); \ … … 697 687 DIM(OUT,IN,OP,C32); \ 698 688 break; \ 699 default: \ 700 psError(__func__, ": Invalid PS_TYPE: %d", IN->type); \ 701 if (OUT != IN) { \ 702 psFree(OUT); \ 703 } \ 704 return NULL; \ 689 default: { \ 690 char* strType; \ 691 PS_TYPE_NAME(strType, IN->type); \ 692 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 693 PS_ERRORTEXT_psMatrix_TYPE_MISMATCH, \ 694 strType); \ 695 if (OUT != IN) { \ 696 psFree(OUT); \ 697 } \ 698 return NULL; \ 699 } \ 705 700 } 706 701 … … 815 810 } \ 816 811 } else { \ 817 psError(__func__, ": Invalid operation: %s", OP); \ 812 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 813 PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED, \ 814 OP); \ 818 815 } 819 816 820 817 psPtr psUnaryOp(psPtr out, psPtr in, char *op) 821 818 { 822 psDimen dimIn = 0; 823 psElemType elTypeIn = 0; 824 psType* psTypeIn = NULL; 825 826 psTypeIn = (psType* ) in; 827 if (psTypeIn == NULL) { 828 psError(__func__, ": Line %d - Null in argument", __LINE__); 829 if (out != in) { 830 psFree(out); 831 } 832 return NULL; 833 } 834 835 if (op == NULL) { 836 psError(__func__, ": Line %d - Null op argument", __LINE__); 837 if (out != in) { 838 psFree(out); 839 } 840 return NULL; 841 } 842 843 dimIn = psTypeIn->dimen; 844 elTypeIn = psTypeIn->type; 819 #define psUnaryOp_EXIT { \ 820 if (out != in) { \ 821 psFree(out); \ 822 } \ 823 if(psTypeIn->dimen==PS_DIMEN_SCALAR && in!=out) { \ 824 psFree(in); \ 825 } \ 826 return NULL; \ 827 } 828 829 psType* psTypeIn = (psType* ) in; 830 831 PS_PTR_CHECK_NULL_GENERAL(in, psUnaryOp_EXIT); 832 PS_PTR_CHECK_NULL_GENERAL(op, psUnaryOp_EXIT); 833 834 psDimen dimIn = psTypeIn->dimen; 835 psElemType elTypeIn = psTypeIn->type; 845 836 846 837 switch (dimIn) { … … 857 848 case PS_DIMEN_TRANSV: 858 849 if (((psVector*)in)->n == 0) { 859 if (out != in) { 860 psFree(out); 861 } 862 psError(__func__, ": Line %d - Vector contains zero elements"); 863 return NULL; 850 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 851 PS_ERRORTEXT_psMatrix_VECTOR_EMPTY); 852 psUnaryOp_EXIT; 864 853 } 865 854 … … 868 857 elTypeIn); 869 858 if (out == NULL) { 870 psError(__func__, "Couldn't create a proper output psVector."); 871 return NULL; 859 psError(PS_ERR_UNKNOWN, false, 860 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 861 psUnaryOp_EXIT; 872 862 } 873 863 … … 876 866 case PS_DIMEN_IMAGE: 877 867 if (((psImage* ) in)->numCols == 0 || ((psImage* ) in)->numRows == 0) { 878 if (out != in) { 879 psFree(out); 880 } 881 psError(__func__, ": Line %d - Image contains zero length row or cols"); 882 return NULL; 868 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 869 PS_ERRORTEXT_psMatrix_IMAGE_EMPTY); 870 psUnaryOp_EXIT; 883 871 } 884 872 … … 888 876 elTypeIn); 889 877 if (out == NULL) { 890 psError(__func__, "Couldn't create a proper output psImage."); 891 return NULL; 878 psError(PS_ERR_UNKNOWN, false, 879 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 880 psUnaryOp_EXIT; 892 881 } 893 882 … … 898 887 psFree(out); 899 888 } 900 psError(__func__, ": Line %d - Invalid dimensionality for in arg: %d", __LINE__, dimIn); 901 return NULL; 889 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 890 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 891 "in", dimIn); 892 psUnaryOp_EXIT; 902 893 } 903 894 -
trunk/psLib/src/dataManip/psMinimize.c
r2269 r2273 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.8 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-11-0 3 03:30:30$11 * @version $Revision: 1.85 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-11-04 01:04:59 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 291 291 292 292 if (y32->n != (1 + mySpline->n)) { 293 psError(__func__, "data size / spline size mismatch (%d %d)\n", 293 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 294 "data size / spline size mismatch (%d %d)\n", 294 295 y32->n, mySpline->n); 295 296 return(NULL); … … 318 319 // Check if these are cubic splines (n==4). If not, psError. 319 320 if (4 != (mySpline->spline[0])->n) { 320 psError(__func__, "Don't know how to generate %d-order splines.", 321 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 322 "Don't know how to generate %d-order splines.", 321 323 (mySpline->spline[0])->n-1); 322 324 return(NULL); … … 952 954 PS_VECTOR_GEN_X_INDEX_STATIC_F64(x64Static, y->n); 953 955 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 954 p _psNormalizeVectorRange(x64Static, -1.0, 1.0);956 psNormalizeVectorRange(x64Static, -1.0, 1.0); 955 957 } 956 958 x64 = x64Static; … … 968 970 tmpPoly = VectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64); 969 971 } else { 970 psError(__func__, "unknown polynomial type.\n"); 972 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 973 "unknown polynomial type.\n"); 971 974 return(NULL); 972 975 } … … 1365 1368 bracket = p_psDetermineBracket2(params, line, paramMask, coords, func); 1366 1369 if (bracket == NULL) { 1367 psError(__func__, "(1) Could not bracket minimum."); 1370 psError(PS_ERR_UNKNOWN, false, 1371 "Could not bracket minimum."); 1368 1372 return(NAN); 1369 1373 } … … 1552 1556 func); 1553 1557 if (isnan(mul)) { 1554 psError(__func__, "Could not perform line minimization (1).\n"); 1558 psError(PS_ERR_UNKNOWN, false, 1559 "Could not perform line minimization"); 1555 1560 psFree(v); 1556 1561 return(false); … … 1592 1597 mul = p_psLineMin(&dummyMin, params, u, myParamMask, coords, func); 1593 1598 if (isnan(mul)) { 1594 psError(__func__, "Could not perform line minimization. (2)\n"); 1599 psError(PS_ERR_UNKNOWN, false, 1600 "Could not perform line minimization."); 1595 1601 psFree(v); 1596 1602 return(false); -
trunk/psLib/src/dataManip/psStats.c
r2269 r2273 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.8 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-11-0 3 03:30:30$11 * @version $Revision: 1.85 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-11-04 01:04:59 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 34 34 #include "psFunctions.h" 35 35 #include "psConstants.h" 36 37 #include "psDataManipErrors.h" 36 38 37 39 /*****************************************************************************/ … … 735 737 736 738 // Ensure that stats->clipIter is within the proper range. 737 if (!((PS_CLIPPED_NUM_ITER_LB <= stats->clipIter) && (stats->clipIter <= PS_CLIPPED_NUM_ITER_UB))) { 738 psError(__func__, "Unallowed value for clipIter (%d).\n", stats->clipIter); 739 return(-1); 740 } 739 PS_INT_CHECK_RANGE(stats->clipIter,PS_CLIPPED_NUM_ITER_LB,PS_CLIPPED_NUM_ITER_UB,-1); 740 741 741 // Ensure that stats->clipSigma is within the proper range. 742 if (!((PS_CLIPPED_SIGMA_LB <= stats->clipSigma) && (stats->clipSigma <= PS_CLIPPED_SIGMA_UB))) { 743 psError(__func__, "Unallowed value for clipSigma (%f).\n", stats->clipSigma); 744 return(-1); 745 } 742 PS_INT_CHECK_RANGE(stats->clipSigma,PS_CLIPPED_SIGMA_LB,PS_CLIPPED_SIGMA_UB,-1); 743 746 744 // We allocate a temporary mask vector since during the iterative 747 745 // steps that follow, we will be masking off additional data points. … … 869 867 p_psNormalizeVectorRangeF64(myData, low, high); 870 868 } else { 871 psError(__func__, "Unalowable data type.\n"); 869 char* strType; 870 PS_TYPE_NAME(strType,myData->type.type); 871 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 872 PS_ERRORTEXT_psStats_NOT_F32_F64, 873 strType); 872 874 } 873 875 } … … 954 956 // Ensure that yVal is within the range of the bins we are using. 955 957 if (!((y->data.F64[0] <= yVal) && (yVal <= y->data.F64[2]))) { 956 printf("((%f), %f, %f)\n", yVal, y->data.F64[0], y->data.F64[2]); 957 psError(__func__, "yVal not within y-range\n"); 958 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 959 PS_ERRORTEXT_psStats_YVAL_OUT_OF_RANGE, 960 (double)yVal,y->data.F64[2],y->data.F64[0]); 958 961 } 959 962 yErr->data.F64[0] = 1.0; … … 1113 1116 1114 1117 if ((LQBinNum < 0) || (UQBinNum < 0)) { 1115 psError(__func__, "Could not determine the robust lower/upper quartile bin numbers."); 1118 psError(PS_ERR_UNKNOWN, true, 1119 PS_ERRORTEXT_psStats_ROBUST_QUARTILE_BINS_FAILED); 1116 1120 return(1); 1117 1121 } 1118 1122 if (medianBinNum < 0) { 1119 psError(__func__, "Could not determine the robust lower/upper quartile bin numbers."); 1123 psError(PS_ERR_UNKNOWN, true, 1124 PS_ERRORTEXT_psStats_ROBUST_QUARTILE_BINS_FAILED); 1120 1125 return(1); 1121 1126 } … … 1174 1179 psVector *y = psVectorAlloc(robustHistogramVector->n, PS_TYPE_F32); 1175 1180 1176 p _psNormalizeVectorRange(robustHistogramVector, 0.0, 1.0);1181 psNormalizeVectorRange(robustHistogramVector, 0.0, 1.0); 1177 1182 for (i=0;i<robustHistogramVector->n;i++) { 1178 1183 myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32); … … 1536 1541 // do nothing 1537 1542 } else { 1538 psError(__func__, "unsupported vector type 0x%x\n", in->type.type); 1543 char* strType; 1544 PS_TYPE_NAME(strType,in->type.type); 1545 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1546 PS_ERRORTEXT_psStats_VECTOR_TYPE_UNSUPPORTED, 1547 strType); 1539 1548 } 1540 1549 return (tmp); … … 1603 1612 (stats->options & PS_STAT_ROBUST_STDEV) || (stats->options & PS_STAT_ROBUST_QUARTILE)) { 1604 1613 if (0 != p_psVectorRobustStats(inF32, mask, maskVal, stats)) { 1605 psError(__func__, "p_psVectorRobustStats() failed.\n"); 1614 psError(PS_ERR_UNKNOWN, false, 1615 PS_ERRORTEXT_psStats_STATS_FAILED); 1606 1616 } 1607 1617 } … … 1609 1619 if ((stats->options & PS_STAT_CLIPPED_MEAN) || (stats->options & PS_STAT_CLIPPED_STDEV)) { 1610 1620 if (0 != p_psVectorClippedStats(inF32, mask, maskVal, stats)) { 1611 psError(__func__, "p_psVectorClippedStats() failed.\n"); 1621 psError(PS_ERR_UNKNOWN, false, 1622 "Failed to calculate statistics for input psVector."); 1612 1623 } 1613 1624 } -
trunk/psLib/src/dataManip/psVectorFFT.c
r2204 r2273 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.2 7$ $Name: not supported by cvs2svn $8 * @date $Date: 2004-1 0-27 00:57:31$7 * @version $Revision: 1.28 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2004-11-04 01:04:59 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 63 63 (fftwf_complex *) out->data.C32, FFTW_BACKWARD, P_FFTW_PLAN_RIGOR); 64 64 } else { 65 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorFFT", 66 PS_ERR_BAD_PARAMETER_VALUE, true, 67 PS_ERRORTEXT_psVectorFFT_DIRECTION_NOTSET); 65 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 66 PS_ERRORTEXT_psVectorFFT_DIRECTION_NOTSET); 68 67 psFree(out); 69 68 return NULL; … … 72 71 /* check if a plan exists now */ 73 72 if (plan == NULL) { 74 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorFFT", 75 PS_ERR_BAD_PARAMETER_TYPE, true, 76 PS_ERRORTEXT_psVectorFFT_FFTW_PLAN_NULL); 73 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 74 PS_ERRORTEXT_psVectorFFT_FFTW_PLAN_NULL); 77 75 psFree(out); 78 76 return NULL; … … 144 142 char* typeStr; 145 143 PS_TYPE_NAME(typeStr,type); 146 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorReal", 147 PS_ERR_BAD_PARAMETER_TYPE, true, 148 PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED, 149 typeStr); 144 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 145 PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED, 146 typeStr); 150 147 psFree(out); 151 148 return NULL; … … 204 201 char* typeStr; 205 202 PS_TYPE_NAME(typeStr,type); 206 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorImaginary", 207 PS_ERR_BAD_PARAMETER_TYPE, true, 208 PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED, 209 typeStr); 203 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 204 PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED, 205 typeStr); 210 206 psFree(out); 211 207 return NULL; … … 237 233 PS_TYPE_NAME(typeStrReal,type); 238 234 PS_TYPE_NAME(typeStrImag,imag->type.type); 239 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorComplex", 240 PS_ERR_BAD_PARAMETER_TYPE, true, 241 PS_ERRORTEXT_psVectorFFT_REAL_IMAG_TYPE_MISMATCH, 242 typeStrReal,typeStrImag); 235 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 236 PS_ERRORTEXT_psVectorFFT_REAL_IMAG_TYPE_MISMATCH, 237 typeStrReal,typeStrImag); 243 238 psFree(out); 244 239 return NULL; … … 272 267 char* typeStr; 273 268 PS_TYPE_NAME(typeStr,type); 274 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorComplex", 275 PS_ERR_BAD_PARAMETER_TYPE, true, 276 PS_ERRORTEXT_psVectorFFT_NONREAL_NOTSUPPORTED, 277 typeStr); 269 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 270 PS_ERRORTEXT_psVectorFFT_NONREAL_NOTSUPPORTED, 271 typeStr); 278 272 psFree(out); 279 273 return NULL; … … 333 327 char* typeStr; 334 328 PS_TYPE_NAME(typeStr,type); 335 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorConjugate", 336 PS_ERR_BAD_PARAMETER_TYPE, true, 337 PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED, 338 typeStr); 329 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 330 PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED, 331 typeStr); 339 332 psFree(out); 340 333 return NULL; … … 414 407 char* typeStr; 415 408 PS_TYPE_NAME(typeStr,type); 416 psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorPowerSpectrum", 417 PS_ERR_BAD_PARAMETER_TYPE, true, 418 PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED, 419 typeStr); 420 psFree(out); 421 return NULL; 422 } 423 424 return out; 425 426 } 409 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 410 PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED, 411 typeStr); 412 psFree(out); 413 return NULL; 414 } 415 416 return out; 417 418 }
Note:
See TracChangeset
for help on using the changeset viewer.
