Changeset 2217
- Timestamp:
- Oct 27, 2004, 11:06:30 AM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 7 edited
-
dataManip/psConstants.h (modified) (5 diffs)
-
dataManip/psFunctions.c (modified) (36 diffs)
-
dataManip/psStats.c (modified) (11 diffs)
-
math/psConstants.h (modified) (5 diffs)
-
math/psPolynomial.c (modified) (36 diffs)
-
math/psSpline.c (modified) (36 diffs)
-
math/psStats.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psConstants.h
r2216 r2217 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-27 2 0:32:49$8 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-27 21:06:30 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 29 29 /***************************************************************************** 30 31 *****************************************************************************/ 32 #define PS_INT_CHECK_NON_NEGATIVE(NAME, RVAL) \ 33 if (NAME < 0) { \ 34 psError(__func__,"%s is less than 0.", #NAME); \ 35 return(RVAL); \ 36 } 37 38 39 40 /***************************************************************************** 30 41 Macros which take a generic psLib type and determine if it is NULL, or has 31 42 the wrong type. … … 48 59 PS_VECTOR macros: 49 60 *****************************************************************************/ 50 #define PS_VECTOR_CHECK_TYPE_F32_OR_F64(VEC, RVAL) \ 51 if ((VEC->type.type != PS_TYPE_F32) && (VEC->type.type != PS_TYPE_F64)) { \ 52 psAbort(__func__, "Bad type for VEC (%d)", VEC->type.type); \ 61 #define PS_VECTOR_CHECK_NULL(NAME, RVAL) \ 62 if (NAME == NULL || NAME->data.V == NULL) { \ 63 psError(__func__,"Unallowable operation: psVector %s or its data is NULL.", #NAME); \ 64 return(RVAL); \ 65 } \ 66 67 #define PS_VECTOR_CHECK_EMPTY(NAME, RVAL) \ 68 if (NAME->n < 1) { \ 69 psError(__func__,"Unallowable operation: psVector %s has no elements.", #NAME); \ 70 return(RVAL); \ 71 } \ 72 73 #define PS_VECTOR_CHECK_TYPE_F32_OR_F64(NAME, RVAL) \ 74 if ((NAME->type.type != PS_TYPE_F32) && (NAME->type.type != PS_TYPE_F64)) { \ 75 psAbort(__func__, "psVector %s: bad type(%d)", #NAME, NAME->type.type); \ 53 76 return(RVAL); \ 54 77 } \ … … 56 79 #define PS_VECTOR_CHECK_TYPE(NAME, TYPE, RVAL) \ 57 80 if (NAME->type.type != TYPE) { \ 58 psError(__func__,"Unallowable operation: %s has incorrect type.", #NAME); \ 59 return(RVAL); \ 60 } 61 62 #define PS_VECTOR_CHECK_NULL(NAME, RVAL) \ 63 if (NAME == NULL || NAME->data.V == NULL) { \ 64 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 65 return(RVAL); \ 66 } \ 67 68 #define PS_VECTOR_CHECK_EMPTY(NAME, RVAL) \ 69 if (NAME->n < 1) { \ 70 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 71 return(RVAL); \ 72 } \ 81 psError(__func__,"Unallowable operation: psVector %s has incorrect type.", #NAME); \ 82 return(RVAL); \ 83 } 73 84 74 85 #define PS_VECTOR_CHECK_SIZE_EQUAL(VEC1, VEC2, RVAL) \ 75 86 if (VEC1->n != VEC2->n) { \ 76 psError(__func__," Vector %s has size %d,Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \87 psError(__func__,"psVector %s has size %d, psVector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \ 77 88 return(RVAL); \ 78 89 } … … 166 177 PS_POLY macros: 167 178 *****************************************************************************/ 168 #define PS_POLY_CHECK_NULL(NAME, NULL) \179 #define PS_POLY_CHECK_NULL(NAME, RVAL) \ 169 180 if (NAME == NULL || NAME->coeff == NULL) { \ 170 181 psError(__func__,"Unallowable operation: polynomial %s or its coeffs is NULL.", #NAME); \ 171 return( NULL); \182 return(RVAL); \ 172 183 } \ 173 184 -
trunk/psLib/src/dataManip/psFunctions.c
r2204 r2217 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-27 00:57:31$9 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-27 21:06:30 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 13 * 14 * XXX: What happens if the polyEVal functions are called with dat of the wrong 15 * type? 16 * 13 17 */ 14 18 /*****************************************************************************/ … … 30 34 #include "psAbort.h" 31 35 #include "psLogMsg.h" 32 33 36 #include "psFunctions.h" 37 #include "psConstants.h" 34 38 /*****************************************************************************/ 35 39 /* DEFINE STATEMENTS */ 36 40 /*****************************************************************************/ 37 /*38 * The following macros take the vector IN as input. If IN is not of39 * the correct type, then a new vector OUT is created of the correct40 * type, and the elements of IN and converted to OUT.41 *42 * If vector IN is the correct type, then OUT is simply set to IN.43 */44 #define PS_CONVERT_VECTOR_F32(IN, OUT) \45 if (IN->type.type != PS_TYPE_F32) { \46 psLogMsg(__func__, PS_LOG_WARN, \47 "Input vector has incorrect type (%d).\n", \48 IN->type); \49 OUT = psVectorAlloc(IN->n, PS_TYPE_F32); \50 \51 if (IN->type.type == PS_TYPE_F64) { \52 for (psS32 i=0;i<IN->n;i++) { \53 OUT->data.F32[i] = (float) (IN->data.F64[i]); \54 } \55 }\56 else { \57 psAbort(__func__, "Wrong type.\n"); \58 } \59 } else { \60 OUT = (psVector *) IN; \61 }62 63 #define PS_CONVERT_VECTOR_F64(IN, OUT) \64 if (IN->type.type != PS_TYPE_F64) { \65 psLogMsg(__func__, PS_LOG_WARN, \66 "Input vector has incorrect type (%d).\n", \67 IN->type); \68 OUT = psVectorAlloc(IN->n, PS_TYPE_F64); \69 \70 if (IN->type.type == PS_TYPE_F32) { \71 for (psS32 i=0;i<IN->n;i++) { \72 OUT->data.F64[i] = (float) (IN->data.F32[i]); \73 } \74 }\75 else { \76 psAbort(__func__, "Wrong type.\n"); \77 } \78 } else { \79 OUT = (psVector *) IN; \80 }81 41 82 42 /*****************************************************************************/ … … 119 79 static psPolynomial1D **CreateChebyshevPolys(psS32 maxChebyPoly) 120 80 { 81 PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL); 82 121 83 psPolynomial1D **chebPolys = NULL; 122 84 psS32 i = 0; … … 187 149 psVector* psGaussianDev(float mean, float sigma, psS32 Npts) 188 150 { 151 PS_INT_CHECK_NON_NEGATIVE(Npts, NULL); 152 189 153 psVector* gauss = NULL; 190 154 const gsl_rng_type *T = NULL; 191 155 gsl_rng *r = NULL; 192 156 psS32 i = 0; 157 193 158 194 159 gauss = psVectorAlloc(Npts, PS_TYPE_F32); … … 212 177 psPolynomialType type) 213 178 { 179 PS_INT_CHECK_NON_NEGATIVE(n, NULL); 180 214 181 psS32 i = 0; 215 182 psPolynomial1D* newPoly = NULL; … … 235 202 psPolynomialType type) 236 203 { 204 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 205 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 206 237 207 psS32 x = 0; 238 208 psS32 y = 0; … … 268 238 psPolynomialType type) 269 239 { 240 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 241 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 242 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 243 270 244 psS32 x = 0; 271 245 psS32 y = 0; … … 310 284 psPolynomialType type) 311 285 { 286 PS_INT_CHECK_NON_NEGATIVE(nW, NULL); 287 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 288 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 289 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 290 312 291 psS32 w = 0; 313 292 psS32 x = 0; … … 522 501 float psPolynomial1DEval(float x, const psPolynomial1D* myPoly) 523 502 { 503 PS_POLY_CHECK_NULL(myPoly, NAN); 504 524 505 if (myPoly->type == PS_POLYNOMIAL_ORD) { 525 506 return(p_psOrdPolynomial1DEval(x, myPoly)); … … 535 516 const psPolynomial1D *myPoly) 536 517 { 518 PS_POLY_CHECK_NULL(myPoly, NULL); 519 PS_VECTOR_CHECK_NULL(x, NULL); 520 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 521 537 522 psVector *tmp; 538 523 psVector *myX; 539 524 psS32 i; 540 525 541 PS_CONVERT_VECTOR_F32(x, myX);542 543 526 tmp = psVectorAlloc(x->n, PS_TYPE_F32); 544 527 for (i=0;i<x->n;i++) { … … 555 538 float p_psOrdPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 556 539 { 540 PS_POLY_CHECK_NULL(myPoly, NAN); 541 557 542 psS32 loop_x = 0; 558 543 psS32 loop_y = 0; … … 577 562 float p_psChebPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 578 563 { 564 PS_POLY_CHECK_NULL(myPoly, NAN); 565 579 566 psS32 loop_x = 0; 580 567 psS32 loop_y = 0; … … 610 597 float psPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 611 598 { 599 PS_POLY_CHECK_NULL(myPoly, NAN); 600 612 601 if (myPoly->type == PS_POLYNOMIAL_ORD) { 613 602 return(p_psOrdPolynomial2DEval(x, y, myPoly)); … … 625 614 const psPolynomial2D *myPoly) 626 615 { 616 PS_POLY_CHECK_NULL(myPoly, NULL); 617 PS_VECTOR_CHECK_NULL(x, NULL); 618 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 619 PS_VECTOR_CHECK_NULL(y, NULL); 620 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 621 627 622 psVector *tmp; 628 623 psVector *myX; … … 631 626 psS32 vecLen=x->n; 632 627 633 PS_CONVERT_VECTOR_F32(x, myX);634 PS_CONVERT_VECTOR_F32(y, myY);635 628 vecLen=x->n; 636 629 if (y->n < vecLen) { … … 727 720 float psPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly) 728 721 { 722 PS_POLY_CHECK_NULL(myPoly, NAN); 723 729 724 if (myPoly->type == PS_POLYNOMIAL_ORD) { 730 725 return(p_psOrdPolynomial3DEval(x, y, z, myPoly)); … … 742 737 const psPolynomial3D *myPoly) 743 738 { 739 PS_POLY_CHECK_NULL(myPoly, NULL); 740 PS_VECTOR_CHECK_NULL(x, NULL); 741 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 742 PS_VECTOR_CHECK_NULL(y, NULL); 743 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 744 PS_VECTOR_CHECK_NULL(z, NULL); 745 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F32, NULL); 746 744 747 psVector *tmp; 745 748 psVector *myX; … … 749 752 psS32 vecLen=x->n; 750 753 751 PS_CONVERT_VECTOR_F32(x, myX);752 PS_CONVERT_VECTOR_F32(y, myY);753 PS_CONVERT_VECTOR_F32(z, myZ);754 754 vecLen=x->n; 755 755 if (y->n < vecLen) { … … 869 869 float psPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly) 870 870 { 871 PS_POLY_CHECK_NULL(myPoly, NAN); 872 871 873 if (myPoly->type == PS_POLYNOMIAL_ORD) { 872 874 return(p_psOrdPolynomial4DEval(w,x,y,z, myPoly)); … … 885 887 const psPolynomial4D *myPoly) 886 888 { 889 PS_POLY_CHECK_NULL(myPoly, NULL); 890 PS_VECTOR_CHECK_NULL(w, NULL); 891 PS_VECTOR_CHECK_TYPE(w, PS_TYPE_F32, NULL); 892 PS_VECTOR_CHECK_NULL(x, NULL); 893 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 894 PS_VECTOR_CHECK_NULL(y, NULL); 895 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 896 PS_VECTOR_CHECK_NULL(z, NULL); 897 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F32, NULL); 898 887 899 psVector *tmp; 888 900 psVector *myW; … … 893 905 psS32 vecLen=x->n; 894 906 895 PS_CONVERT_VECTOR_F32(w, myW);896 PS_CONVERT_VECTOR_F32(x, myX);897 PS_CONVERT_VECTOR_F32(y, myY);898 PS_CONVERT_VECTOR_F32(z, myZ);899 907 vecLen=w->n; 900 908 if (y->n < vecLen) { … … 939 947 psPolynomialType type) 940 948 { 949 PS_INT_CHECK_NON_NEGATIVE(n, NULL); 950 941 951 psS32 i = 0; 942 952 psDPolynomial1D* newPoly = NULL; … … 962 972 psPolynomialType type) 963 973 { 974 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 975 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 976 964 977 psS32 x = 0; 965 978 psS32 y = 0; … … 995 1008 psPolynomialType type) 996 1009 { 1010 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 1011 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 1012 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 1013 997 1014 psS32 x = 0; 998 1015 psS32 y = 0; … … 1037 1054 psPolynomialType type) 1038 1055 { 1056 PS_INT_CHECK_NON_NEGATIVE(nW, NULL); 1057 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 1058 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 1059 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 1060 1039 1061 psS32 w = 0; 1040 1062 psS32 x = 0; … … 1207 1229 double psDPolynomial1DEval(double x, const psDPolynomial1D* myPoly) 1208 1230 { 1231 PS_POLY_CHECK_NULL(myPoly, NAN); 1232 1209 1233 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1210 1234 return(p_psDOrdPolynomial1DEval(x, myPoly)); … … 1220 1244 const psDPolynomial1D *myPoly) 1221 1245 { 1246 PS_POLY_CHECK_NULL(myPoly, NULL); 1247 PS_VECTOR_CHECK_NULL(x, NULL); 1248 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1249 1222 1250 psVector *tmp; 1223 1251 psVector *myX; 1224 1252 psS32 i; 1225 1226 PS_CONVERT_VECTOR_F64(x, myX);1227 1253 1228 1254 tmp = psVectorAlloc(x->n, PS_TYPE_F64); … … 1297 1323 double psDPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly) 1298 1324 { 1325 PS_POLY_CHECK_NULL(myPoly, NAN); 1326 1299 1327 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1300 1328 return(p_psDOrdPolynomial2DEval(x, y, myPoly)); … … 1311 1339 const psDPolynomial2D *myPoly) 1312 1340 { 1341 PS_POLY_CHECK_NULL(myPoly, NULL); 1342 PS_VECTOR_CHECK_NULL(x, NULL); 1343 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1344 PS_VECTOR_CHECK_NULL(y, NULL); 1345 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1346 1313 1347 psVector *tmp; 1314 1348 psVector *myX; … … 1317 1351 psS32 vecLen=x->n; 1318 1352 1319 PS_CONVERT_VECTOR_F64(x, myX);1320 PS_CONVERT_VECTOR_F64(y, myY);1321 1353 vecLen=x->n; 1322 1354 if (y->n < vecLen) { … … 1413 1445 double psDPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly) 1414 1446 { 1447 PS_POLY_CHECK_NULL(myPoly, NAN); 1448 1415 1449 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1416 1450 return(p_psDOrdPolynomial3DEval(x, y, z, myPoly)); … … 1428 1462 const psDPolynomial3D *myPoly) 1429 1463 { 1464 PS_POLY_CHECK_NULL(myPoly, NULL); 1465 PS_VECTOR_CHECK_NULL(x, NULL); 1466 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1467 PS_VECTOR_CHECK_NULL(y, NULL); 1468 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1469 PS_VECTOR_CHECK_NULL(z, NULL); 1470 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F64, NULL); 1471 1430 1472 psVector *tmp; 1431 1473 psVector *myX; … … 1435 1477 psS32 vecLen=x->n; 1436 1478 1437 PS_CONVERT_VECTOR_F64(x, myX);1438 PS_CONVERT_VECTOR_F64(y, myY);1439 PS_CONVERT_VECTOR_F64(z, myZ);1440 1479 vecLen=x->n; 1441 1480 if (y->n < vecLen) { … … 1557 1596 double psDPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly) 1558 1597 { 1598 PS_POLY_CHECK_NULL(myPoly, NAN); 1599 1559 1600 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1560 1601 return(p_psDOrdPolynomial4DEval(w,x,y,z, myPoly)); … … 1573 1614 const psDPolynomial4D *myPoly) 1574 1615 { 1616 PS_POLY_CHECK_NULL(myPoly, NULL); 1617 PS_VECTOR_CHECK_NULL(w, NULL); 1618 PS_VECTOR_CHECK_TYPE(w, PS_TYPE_F64, NULL); 1619 PS_VECTOR_CHECK_NULL(x, NULL); 1620 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1621 PS_VECTOR_CHECK_NULL(y, NULL); 1622 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1623 PS_VECTOR_CHECK_NULL(z, NULL); 1624 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F64, NULL); 1625 1575 1626 psVector *tmp; 1576 1627 psVector *myW; … … 1581 1632 psS32 vecLen=x->n; 1582 1633 1583 PS_CONVERT_VECTOR_F64(w, myW);1584 PS_CONVERT_VECTOR_F64(x, myX);1585 PS_CONVERT_VECTOR_F64(y, myY);1586 PS_CONVERT_VECTOR_F64(z, myZ);1587 1634 vecLen=w->n; 1588 1635 if (y->n < vecLen) { -
trunk/psLib/src/dataManip/psStats.c
r2213 r2217 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.7 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-27 2 0:11:47$13 *11 * @version $Revision: 1.74 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-27 21:06:30 $ 13 n * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 15 */ … … 39 39 /* DEFINE STATEMENTS */ 40 40 /*****************************************************************************/ 41 // will use robust statistical methods. 42 #define GAUSS_WIDTH 5 // The width of the Gaussian or boxcar smoothing. 43 #define CLIPPED_NUM_ITER_LB 1 44 #define CLIPPED_NUM_ITER_UB 10 45 #define CLIPPED_SIGMA_LB 1.0 46 #define CLIPPED_SIGMA_UB 10.0 47 #define true 1 48 #define false 0 49 #define MY_MAX_FLOAT HUGE 50 #define MAX_ITERATIONS 10 51 52 void p_psVectorRobustStats(const psVector* restrict myVector, 53 const psVector* restrict maskVector, psU32 maskVal, psStats* stats); 54 55 41 #define PS_GAUSS_WIDTH 5 // The width of the Gaussian or boxcar smoothing. 42 #define PS_CLIPPED_NUM_ITER_LB 1 43 #define PS_CLIPPED_NUM_ITER_UB 10 44 #define PS_CLIPPED_SIGMA_LB 1.0 45 #define PS_CLIPPED_SIGMA_UB 10.0 46 #define PS_MAX_FLOAT HUGE 47 #define PS_POLY_MEDIAN_MAX_ITERATIONS 10 48 49 #define PS_BIN_MIDPOINT(HISTOGRAM, BIN_NUM) \ 50 (0.5 * (HISTOGRAM->bounds->data.F32[(BIN_NUM)] + HISTOGRAM->bounds->data.F32[(BIN_NUM)+1])) 56 51 /*****************************************************************************/ 57 52 /* TYPE DEFINITIONS */ … … 59 54 psVector* p_psConvertToF32(psVector* in); 60 55 56 void p_psVectorRobustStats(const psVector* restrict myVector, 57 const psVector* restrict maskVector, 58 psU32 maskVal, 59 psStats* stats); 61 60 /*****************************************************************************/ 62 61 /* GLOBAL VARIABLES */ … … 245 244 { 246 245 psS32 i = 0; // Loop index variable 247 float max = - MY_MAX_FLOAT; // The calculated maximum246 float max = -PS_MAX_FLOAT; // The calculated maximum 248 247 float rangeMin = 0.0; // Exclude data below this 249 248 float rangeMax = 0.0; // Exclude date above this … … 306 305 { 307 306 psS32 i = 0; // Loop index variable 308 float min = MY_MAX_FLOAT; // The calculated maximum307 float min = PS_MAX_FLOAT; // The calculated maximum 309 308 float rangeMin = 0.0; // Exclude data below this 310 309 float rangeMax = 0.0; // Exclude date above this … … 493 492 robustHistogram with a Gaussian of width sigma. 494 493 *****************************************************************************/ 495 #define GAUSS_WIDTH_OTHER 5.0496 494 psVector* p_psVectorSmoothHistGaussian(psHistogram* robustHistogram, 497 495 float sigma) … … 521 519 // warnings? 522 520 523 x.data.F32 = iMid - ( GAUSS_WIDTH * sigma);521 x.data.F32 = iMid - (PS_GAUSS_WIDTH * sigma); 524 522 if ((x.data.F32 >= firstBound) && (x.data.F32 <= lastBound)) { 525 523 jMin = p_psVectorBinDisect(robustHistogram->bounds, &x); … … 531 529 } 532 530 533 x.data.F32 = iMid + ( GAUSS_WIDTH * sigma);531 x.data.F32 = iMid + (PS_GAUSS_WIDTH * sigma); 534 532 if ((x.data.F32 >= firstBound) && (x.data.F32 <= lastBound)) { 535 533 jMax = p_psVectorBinDisect(robustHistogram->bounds, &x); … … 744 742 745 743 // Endure that stats->clipIter is within the proper range. 746 if (!(( CLIPPED_NUM_ITER_LB <= stats->clipIter) && (stats->clipIter <=CLIPPED_NUM_ITER_UB))) {744 if (!((PS_CLIPPED_NUM_ITER_LB <= stats->clipIter) && (stats->clipIter <= PS_CLIPPED_NUM_ITER_UB))) { 747 745 psAbort(__func__, "Unallowed value for clipIter (%d).\n", stats->clipIter); 748 746 } 749 747 // Endure that stats->clipSigma is within the proper range. 750 if (!(( CLIPPED_SIGMA_LB <= stats->clipSigma) && (stats->clipSigma <=CLIPPED_SIGMA_UB))) {748 if (!((PS_CLIPPED_SIGMA_LB <= stats->clipSigma) && (stats->clipSigma <= PS_CLIPPED_SIGMA_UB))) { 751 749 psAbort(__func__, "Unallowed value for clipSigma (%f).\n", stats->clipSigma); 752 750 } … … 996 994 // printf("p_ps1DPolyMedian(%f, %f, %f) \n", rangeLow, rangeHigh, getThisValue); 997 995 998 while (numIterations < MAX_ITERATIONS) {996 while (numIterations < PS_POLY_MEDIAN_MAX_ITERATIONS) { 999 997 midpoint = (rangeHigh + rangeLow) / 2.0; 1000 998 if (fabs(midpoint - oldMidpoint) <= FLT_EPSILON) { … … 1099 1097 return(tmpFloat); 1100 1098 } 1101 1102 #define PS_BIN_MIDPOINT(HISTOGRAM, BIN_NUM) \1103 (0.5 * (HISTOGRAM->bounds->data.F32[(BIN_NUM)] + HISTOGRAM->bounds->data.F32[(BIN_NUM)+1]))1104 1099 1105 1100 /****************************************************************************** -
trunk/psLib/src/math/psConstants.h
r2216 r2217 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-27 2 0:32:49$8 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-27 21:06:30 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 29 29 /***************************************************************************** 30 31 *****************************************************************************/ 32 #define PS_INT_CHECK_NON_NEGATIVE(NAME, RVAL) \ 33 if (NAME < 0) { \ 34 psError(__func__,"%s is less than 0.", #NAME); \ 35 return(RVAL); \ 36 } 37 38 39 40 /***************************************************************************** 30 41 Macros which take a generic psLib type and determine if it is NULL, or has 31 42 the wrong type. … … 48 59 PS_VECTOR macros: 49 60 *****************************************************************************/ 50 #define PS_VECTOR_CHECK_TYPE_F32_OR_F64(VEC, RVAL) \ 51 if ((VEC->type.type != PS_TYPE_F32) && (VEC->type.type != PS_TYPE_F64)) { \ 52 psAbort(__func__, "Bad type for VEC (%d)", VEC->type.type); \ 61 #define PS_VECTOR_CHECK_NULL(NAME, RVAL) \ 62 if (NAME == NULL || NAME->data.V == NULL) { \ 63 psError(__func__,"Unallowable operation: psVector %s or its data is NULL.", #NAME); \ 64 return(RVAL); \ 65 } \ 66 67 #define PS_VECTOR_CHECK_EMPTY(NAME, RVAL) \ 68 if (NAME->n < 1) { \ 69 psError(__func__,"Unallowable operation: psVector %s has no elements.", #NAME); \ 70 return(RVAL); \ 71 } \ 72 73 #define PS_VECTOR_CHECK_TYPE_F32_OR_F64(NAME, RVAL) \ 74 if ((NAME->type.type != PS_TYPE_F32) && (NAME->type.type != PS_TYPE_F64)) { \ 75 psAbort(__func__, "psVector %s: bad type(%d)", #NAME, NAME->type.type); \ 53 76 return(RVAL); \ 54 77 } \ … … 56 79 #define PS_VECTOR_CHECK_TYPE(NAME, TYPE, RVAL) \ 57 80 if (NAME->type.type != TYPE) { \ 58 psError(__func__,"Unallowable operation: %s has incorrect type.", #NAME); \ 59 return(RVAL); \ 60 } 61 62 #define PS_VECTOR_CHECK_NULL(NAME, RVAL) \ 63 if (NAME == NULL || NAME->data.V == NULL) { \ 64 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 65 return(RVAL); \ 66 } \ 67 68 #define PS_VECTOR_CHECK_EMPTY(NAME, RVAL) \ 69 if (NAME->n < 1) { \ 70 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 71 return(RVAL); \ 72 } \ 81 psError(__func__,"Unallowable operation: psVector %s has incorrect type.", #NAME); \ 82 return(RVAL); \ 83 } 73 84 74 85 #define PS_VECTOR_CHECK_SIZE_EQUAL(VEC1, VEC2, RVAL) \ 75 86 if (VEC1->n != VEC2->n) { \ 76 psError(__func__," Vector %s has size %d,Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \87 psError(__func__,"psVector %s has size %d, psVector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \ 77 88 return(RVAL); \ 78 89 } … … 166 177 PS_POLY macros: 167 178 *****************************************************************************/ 168 #define PS_POLY_CHECK_NULL(NAME, NULL) \179 #define PS_POLY_CHECK_NULL(NAME, RVAL) \ 169 180 if (NAME == NULL || NAME->coeff == NULL) { \ 170 181 psError(__func__,"Unallowable operation: polynomial %s or its coeffs is NULL.", #NAME); \ 171 return( NULL); \182 return(RVAL); \ 172 183 } \ 173 184 -
trunk/psLib/src/math/psPolynomial.c
r2204 r2217 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-27 00:57:31$9 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-27 21:06:30 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 13 * 14 * XXX: What happens if the polyEVal functions are called with dat of the wrong 15 * type? 16 * 13 17 */ 14 18 /*****************************************************************************/ … … 30 34 #include "psAbort.h" 31 35 #include "psLogMsg.h" 32 33 36 #include "psFunctions.h" 37 #include "psConstants.h" 34 38 /*****************************************************************************/ 35 39 /* DEFINE STATEMENTS */ 36 40 /*****************************************************************************/ 37 /*38 * The following macros take the vector IN as input. If IN is not of39 * the correct type, then a new vector OUT is created of the correct40 * type, and the elements of IN and converted to OUT.41 *42 * If vector IN is the correct type, then OUT is simply set to IN.43 */44 #define PS_CONVERT_VECTOR_F32(IN, OUT) \45 if (IN->type.type != PS_TYPE_F32) { \46 psLogMsg(__func__, PS_LOG_WARN, \47 "Input vector has incorrect type (%d).\n", \48 IN->type); \49 OUT = psVectorAlloc(IN->n, PS_TYPE_F32); \50 \51 if (IN->type.type == PS_TYPE_F64) { \52 for (psS32 i=0;i<IN->n;i++) { \53 OUT->data.F32[i] = (float) (IN->data.F64[i]); \54 } \55 }\56 else { \57 psAbort(__func__, "Wrong type.\n"); \58 } \59 } else { \60 OUT = (psVector *) IN; \61 }62 63 #define PS_CONVERT_VECTOR_F64(IN, OUT) \64 if (IN->type.type != PS_TYPE_F64) { \65 psLogMsg(__func__, PS_LOG_WARN, \66 "Input vector has incorrect type (%d).\n", \67 IN->type); \68 OUT = psVectorAlloc(IN->n, PS_TYPE_F64); \69 \70 if (IN->type.type == PS_TYPE_F32) { \71 for (psS32 i=0;i<IN->n;i++) { \72 OUT->data.F64[i] = (float) (IN->data.F32[i]); \73 } \74 }\75 else { \76 psAbort(__func__, "Wrong type.\n"); \77 } \78 } else { \79 OUT = (psVector *) IN; \80 }81 41 82 42 /*****************************************************************************/ … … 119 79 static psPolynomial1D **CreateChebyshevPolys(psS32 maxChebyPoly) 120 80 { 81 PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL); 82 121 83 psPolynomial1D **chebPolys = NULL; 122 84 psS32 i = 0; … … 187 149 psVector* psGaussianDev(float mean, float sigma, psS32 Npts) 188 150 { 151 PS_INT_CHECK_NON_NEGATIVE(Npts, NULL); 152 189 153 psVector* gauss = NULL; 190 154 const gsl_rng_type *T = NULL; 191 155 gsl_rng *r = NULL; 192 156 psS32 i = 0; 157 193 158 194 159 gauss = psVectorAlloc(Npts, PS_TYPE_F32); … … 212 177 psPolynomialType type) 213 178 { 179 PS_INT_CHECK_NON_NEGATIVE(n, NULL); 180 214 181 psS32 i = 0; 215 182 psPolynomial1D* newPoly = NULL; … … 235 202 psPolynomialType type) 236 203 { 204 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 205 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 206 237 207 psS32 x = 0; 238 208 psS32 y = 0; … … 268 238 psPolynomialType type) 269 239 { 240 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 241 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 242 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 243 270 244 psS32 x = 0; 271 245 psS32 y = 0; … … 310 284 psPolynomialType type) 311 285 { 286 PS_INT_CHECK_NON_NEGATIVE(nW, NULL); 287 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 288 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 289 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 290 312 291 psS32 w = 0; 313 292 psS32 x = 0; … … 522 501 float psPolynomial1DEval(float x, const psPolynomial1D* myPoly) 523 502 { 503 PS_POLY_CHECK_NULL(myPoly, NAN); 504 524 505 if (myPoly->type == PS_POLYNOMIAL_ORD) { 525 506 return(p_psOrdPolynomial1DEval(x, myPoly)); … … 535 516 const psPolynomial1D *myPoly) 536 517 { 518 PS_POLY_CHECK_NULL(myPoly, NULL); 519 PS_VECTOR_CHECK_NULL(x, NULL); 520 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 521 537 522 psVector *tmp; 538 523 psVector *myX; 539 524 psS32 i; 540 525 541 PS_CONVERT_VECTOR_F32(x, myX);542 543 526 tmp = psVectorAlloc(x->n, PS_TYPE_F32); 544 527 for (i=0;i<x->n;i++) { … … 555 538 float p_psOrdPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 556 539 { 540 PS_POLY_CHECK_NULL(myPoly, NAN); 541 557 542 psS32 loop_x = 0; 558 543 psS32 loop_y = 0; … … 577 562 float p_psChebPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 578 563 { 564 PS_POLY_CHECK_NULL(myPoly, NAN); 565 579 566 psS32 loop_x = 0; 580 567 psS32 loop_y = 0; … … 610 597 float psPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 611 598 { 599 PS_POLY_CHECK_NULL(myPoly, NAN); 600 612 601 if (myPoly->type == PS_POLYNOMIAL_ORD) { 613 602 return(p_psOrdPolynomial2DEval(x, y, myPoly)); … … 625 614 const psPolynomial2D *myPoly) 626 615 { 616 PS_POLY_CHECK_NULL(myPoly, NULL); 617 PS_VECTOR_CHECK_NULL(x, NULL); 618 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 619 PS_VECTOR_CHECK_NULL(y, NULL); 620 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 621 627 622 psVector *tmp; 628 623 psVector *myX; … … 631 626 psS32 vecLen=x->n; 632 627 633 PS_CONVERT_VECTOR_F32(x, myX);634 PS_CONVERT_VECTOR_F32(y, myY);635 628 vecLen=x->n; 636 629 if (y->n < vecLen) { … … 727 720 float psPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly) 728 721 { 722 PS_POLY_CHECK_NULL(myPoly, NAN); 723 729 724 if (myPoly->type == PS_POLYNOMIAL_ORD) { 730 725 return(p_psOrdPolynomial3DEval(x, y, z, myPoly)); … … 742 737 const psPolynomial3D *myPoly) 743 738 { 739 PS_POLY_CHECK_NULL(myPoly, NULL); 740 PS_VECTOR_CHECK_NULL(x, NULL); 741 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 742 PS_VECTOR_CHECK_NULL(y, NULL); 743 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 744 PS_VECTOR_CHECK_NULL(z, NULL); 745 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F32, NULL); 746 744 747 psVector *tmp; 745 748 psVector *myX; … … 749 752 psS32 vecLen=x->n; 750 753 751 PS_CONVERT_VECTOR_F32(x, myX);752 PS_CONVERT_VECTOR_F32(y, myY);753 PS_CONVERT_VECTOR_F32(z, myZ);754 754 vecLen=x->n; 755 755 if (y->n < vecLen) { … … 869 869 float psPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly) 870 870 { 871 PS_POLY_CHECK_NULL(myPoly, NAN); 872 871 873 if (myPoly->type == PS_POLYNOMIAL_ORD) { 872 874 return(p_psOrdPolynomial4DEval(w,x,y,z, myPoly)); … … 885 887 const psPolynomial4D *myPoly) 886 888 { 889 PS_POLY_CHECK_NULL(myPoly, NULL); 890 PS_VECTOR_CHECK_NULL(w, NULL); 891 PS_VECTOR_CHECK_TYPE(w, PS_TYPE_F32, NULL); 892 PS_VECTOR_CHECK_NULL(x, NULL); 893 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 894 PS_VECTOR_CHECK_NULL(y, NULL); 895 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 896 PS_VECTOR_CHECK_NULL(z, NULL); 897 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F32, NULL); 898 887 899 psVector *tmp; 888 900 psVector *myW; … … 893 905 psS32 vecLen=x->n; 894 906 895 PS_CONVERT_VECTOR_F32(w, myW);896 PS_CONVERT_VECTOR_F32(x, myX);897 PS_CONVERT_VECTOR_F32(y, myY);898 PS_CONVERT_VECTOR_F32(z, myZ);899 907 vecLen=w->n; 900 908 if (y->n < vecLen) { … … 939 947 psPolynomialType type) 940 948 { 949 PS_INT_CHECK_NON_NEGATIVE(n, NULL); 950 941 951 psS32 i = 0; 942 952 psDPolynomial1D* newPoly = NULL; … … 962 972 psPolynomialType type) 963 973 { 974 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 975 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 976 964 977 psS32 x = 0; 965 978 psS32 y = 0; … … 995 1008 psPolynomialType type) 996 1009 { 1010 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 1011 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 1012 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 1013 997 1014 psS32 x = 0; 998 1015 psS32 y = 0; … … 1037 1054 psPolynomialType type) 1038 1055 { 1056 PS_INT_CHECK_NON_NEGATIVE(nW, NULL); 1057 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 1058 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 1059 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 1060 1039 1061 psS32 w = 0; 1040 1062 psS32 x = 0; … … 1207 1229 double psDPolynomial1DEval(double x, const psDPolynomial1D* myPoly) 1208 1230 { 1231 PS_POLY_CHECK_NULL(myPoly, NAN); 1232 1209 1233 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1210 1234 return(p_psDOrdPolynomial1DEval(x, myPoly)); … … 1220 1244 const psDPolynomial1D *myPoly) 1221 1245 { 1246 PS_POLY_CHECK_NULL(myPoly, NULL); 1247 PS_VECTOR_CHECK_NULL(x, NULL); 1248 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1249 1222 1250 psVector *tmp; 1223 1251 psVector *myX; 1224 1252 psS32 i; 1225 1226 PS_CONVERT_VECTOR_F64(x, myX);1227 1253 1228 1254 tmp = psVectorAlloc(x->n, PS_TYPE_F64); … … 1297 1323 double psDPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly) 1298 1324 { 1325 PS_POLY_CHECK_NULL(myPoly, NAN); 1326 1299 1327 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1300 1328 return(p_psDOrdPolynomial2DEval(x, y, myPoly)); … … 1311 1339 const psDPolynomial2D *myPoly) 1312 1340 { 1341 PS_POLY_CHECK_NULL(myPoly, NULL); 1342 PS_VECTOR_CHECK_NULL(x, NULL); 1343 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1344 PS_VECTOR_CHECK_NULL(y, NULL); 1345 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1346 1313 1347 psVector *tmp; 1314 1348 psVector *myX; … … 1317 1351 psS32 vecLen=x->n; 1318 1352 1319 PS_CONVERT_VECTOR_F64(x, myX);1320 PS_CONVERT_VECTOR_F64(y, myY);1321 1353 vecLen=x->n; 1322 1354 if (y->n < vecLen) { … … 1413 1445 double psDPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly) 1414 1446 { 1447 PS_POLY_CHECK_NULL(myPoly, NAN); 1448 1415 1449 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1416 1450 return(p_psDOrdPolynomial3DEval(x, y, z, myPoly)); … … 1428 1462 const psDPolynomial3D *myPoly) 1429 1463 { 1464 PS_POLY_CHECK_NULL(myPoly, NULL); 1465 PS_VECTOR_CHECK_NULL(x, NULL); 1466 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1467 PS_VECTOR_CHECK_NULL(y, NULL); 1468 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1469 PS_VECTOR_CHECK_NULL(z, NULL); 1470 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F64, NULL); 1471 1430 1472 psVector *tmp; 1431 1473 psVector *myX; … … 1435 1477 psS32 vecLen=x->n; 1436 1478 1437 PS_CONVERT_VECTOR_F64(x, myX);1438 PS_CONVERT_VECTOR_F64(y, myY);1439 PS_CONVERT_VECTOR_F64(z, myZ);1440 1479 vecLen=x->n; 1441 1480 if (y->n < vecLen) { … … 1557 1596 double psDPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly) 1558 1597 { 1598 PS_POLY_CHECK_NULL(myPoly, NAN); 1599 1559 1600 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1560 1601 return(p_psDOrdPolynomial4DEval(w,x,y,z, myPoly)); … … 1573 1614 const psDPolynomial4D *myPoly) 1574 1615 { 1616 PS_POLY_CHECK_NULL(myPoly, NULL); 1617 PS_VECTOR_CHECK_NULL(w, NULL); 1618 PS_VECTOR_CHECK_TYPE(w, PS_TYPE_F64, NULL); 1619 PS_VECTOR_CHECK_NULL(x, NULL); 1620 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1621 PS_VECTOR_CHECK_NULL(y, NULL); 1622 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1623 PS_VECTOR_CHECK_NULL(z, NULL); 1624 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F64, NULL); 1625 1575 1626 psVector *tmp; 1576 1627 psVector *myW; … … 1581 1632 psS32 vecLen=x->n; 1582 1633 1583 PS_CONVERT_VECTOR_F64(w, myW);1584 PS_CONVERT_VECTOR_F64(x, myX);1585 PS_CONVERT_VECTOR_F64(y, myY);1586 PS_CONVERT_VECTOR_F64(z, myZ);1587 1634 vecLen=w->n; 1588 1635 if (y->n < vecLen) { -
trunk/psLib/src/math/psSpline.c
r2204 r2217 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-27 00:57:31$9 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-27 21:06:30 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 13 * 14 * XXX: What happens if the polyEVal functions are called with dat of the wrong 15 * type? 16 * 13 17 */ 14 18 /*****************************************************************************/ … … 30 34 #include "psAbort.h" 31 35 #include "psLogMsg.h" 32 33 36 #include "psFunctions.h" 37 #include "psConstants.h" 34 38 /*****************************************************************************/ 35 39 /* DEFINE STATEMENTS */ 36 40 /*****************************************************************************/ 37 /*38 * The following macros take the vector IN as input. If IN is not of39 * the correct type, then a new vector OUT is created of the correct40 * type, and the elements of IN and converted to OUT.41 *42 * If vector IN is the correct type, then OUT is simply set to IN.43 */44 #define PS_CONVERT_VECTOR_F32(IN, OUT) \45 if (IN->type.type != PS_TYPE_F32) { \46 psLogMsg(__func__, PS_LOG_WARN, \47 "Input vector has incorrect type (%d).\n", \48 IN->type); \49 OUT = psVectorAlloc(IN->n, PS_TYPE_F32); \50 \51 if (IN->type.type == PS_TYPE_F64) { \52 for (psS32 i=0;i<IN->n;i++) { \53 OUT->data.F32[i] = (float) (IN->data.F64[i]); \54 } \55 }\56 else { \57 psAbort(__func__, "Wrong type.\n"); \58 } \59 } else { \60 OUT = (psVector *) IN; \61 }62 63 #define PS_CONVERT_VECTOR_F64(IN, OUT) \64 if (IN->type.type != PS_TYPE_F64) { \65 psLogMsg(__func__, PS_LOG_WARN, \66 "Input vector has incorrect type (%d).\n", \67 IN->type); \68 OUT = psVectorAlloc(IN->n, PS_TYPE_F64); \69 \70 if (IN->type.type == PS_TYPE_F32) { \71 for (psS32 i=0;i<IN->n;i++) { \72 OUT->data.F64[i] = (float) (IN->data.F32[i]); \73 } \74 }\75 else { \76 psAbort(__func__, "Wrong type.\n"); \77 } \78 } else { \79 OUT = (psVector *) IN; \80 }81 41 82 42 /*****************************************************************************/ … … 119 79 static psPolynomial1D **CreateChebyshevPolys(psS32 maxChebyPoly) 120 80 { 81 PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL); 82 121 83 psPolynomial1D **chebPolys = NULL; 122 84 psS32 i = 0; … … 187 149 psVector* psGaussianDev(float mean, float sigma, psS32 Npts) 188 150 { 151 PS_INT_CHECK_NON_NEGATIVE(Npts, NULL); 152 189 153 psVector* gauss = NULL; 190 154 const gsl_rng_type *T = NULL; 191 155 gsl_rng *r = NULL; 192 156 psS32 i = 0; 157 193 158 194 159 gauss = psVectorAlloc(Npts, PS_TYPE_F32); … … 212 177 psPolynomialType type) 213 178 { 179 PS_INT_CHECK_NON_NEGATIVE(n, NULL); 180 214 181 psS32 i = 0; 215 182 psPolynomial1D* newPoly = NULL; … … 235 202 psPolynomialType type) 236 203 { 204 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 205 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 206 237 207 psS32 x = 0; 238 208 psS32 y = 0; … … 268 238 psPolynomialType type) 269 239 { 240 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 241 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 242 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 243 270 244 psS32 x = 0; 271 245 psS32 y = 0; … … 310 284 psPolynomialType type) 311 285 { 286 PS_INT_CHECK_NON_NEGATIVE(nW, NULL); 287 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 288 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 289 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 290 312 291 psS32 w = 0; 313 292 psS32 x = 0; … … 522 501 float psPolynomial1DEval(float x, const psPolynomial1D* myPoly) 523 502 { 503 PS_POLY_CHECK_NULL(myPoly, NAN); 504 524 505 if (myPoly->type == PS_POLYNOMIAL_ORD) { 525 506 return(p_psOrdPolynomial1DEval(x, myPoly)); … … 535 516 const psPolynomial1D *myPoly) 536 517 { 518 PS_POLY_CHECK_NULL(myPoly, NULL); 519 PS_VECTOR_CHECK_NULL(x, NULL); 520 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 521 537 522 psVector *tmp; 538 523 psVector *myX; 539 524 psS32 i; 540 525 541 PS_CONVERT_VECTOR_F32(x, myX);542 543 526 tmp = psVectorAlloc(x->n, PS_TYPE_F32); 544 527 for (i=0;i<x->n;i++) { … … 555 538 float p_psOrdPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 556 539 { 540 PS_POLY_CHECK_NULL(myPoly, NAN); 541 557 542 psS32 loop_x = 0; 558 543 psS32 loop_y = 0; … … 577 562 float p_psChebPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 578 563 { 564 PS_POLY_CHECK_NULL(myPoly, NAN); 565 579 566 psS32 loop_x = 0; 580 567 psS32 loop_y = 0; … … 610 597 float psPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly) 611 598 { 599 PS_POLY_CHECK_NULL(myPoly, NAN); 600 612 601 if (myPoly->type == PS_POLYNOMIAL_ORD) { 613 602 return(p_psOrdPolynomial2DEval(x, y, myPoly)); … … 625 614 const psPolynomial2D *myPoly) 626 615 { 616 PS_POLY_CHECK_NULL(myPoly, NULL); 617 PS_VECTOR_CHECK_NULL(x, NULL); 618 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 619 PS_VECTOR_CHECK_NULL(y, NULL); 620 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 621 627 622 psVector *tmp; 628 623 psVector *myX; … … 631 626 psS32 vecLen=x->n; 632 627 633 PS_CONVERT_VECTOR_F32(x, myX);634 PS_CONVERT_VECTOR_F32(y, myY);635 628 vecLen=x->n; 636 629 if (y->n < vecLen) { … … 727 720 float psPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly) 728 721 { 722 PS_POLY_CHECK_NULL(myPoly, NAN); 723 729 724 if (myPoly->type == PS_POLYNOMIAL_ORD) { 730 725 return(p_psOrdPolynomial3DEval(x, y, z, myPoly)); … … 742 737 const psPolynomial3D *myPoly) 743 738 { 739 PS_POLY_CHECK_NULL(myPoly, NULL); 740 PS_VECTOR_CHECK_NULL(x, NULL); 741 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 742 PS_VECTOR_CHECK_NULL(y, NULL); 743 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 744 PS_VECTOR_CHECK_NULL(z, NULL); 745 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F32, NULL); 746 744 747 psVector *tmp; 745 748 psVector *myX; … … 749 752 psS32 vecLen=x->n; 750 753 751 PS_CONVERT_VECTOR_F32(x, myX);752 PS_CONVERT_VECTOR_F32(y, myY);753 PS_CONVERT_VECTOR_F32(z, myZ);754 754 vecLen=x->n; 755 755 if (y->n < vecLen) { … … 869 869 float psPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly) 870 870 { 871 PS_POLY_CHECK_NULL(myPoly, NAN); 872 871 873 if (myPoly->type == PS_POLYNOMIAL_ORD) { 872 874 return(p_psOrdPolynomial4DEval(w,x,y,z, myPoly)); … … 885 887 const psPolynomial4D *myPoly) 886 888 { 889 PS_POLY_CHECK_NULL(myPoly, NULL); 890 PS_VECTOR_CHECK_NULL(w, NULL); 891 PS_VECTOR_CHECK_TYPE(w, PS_TYPE_F32, NULL); 892 PS_VECTOR_CHECK_NULL(x, NULL); 893 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 894 PS_VECTOR_CHECK_NULL(y, NULL); 895 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 896 PS_VECTOR_CHECK_NULL(z, NULL); 897 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F32, NULL); 898 887 899 psVector *tmp; 888 900 psVector *myW; … … 893 905 psS32 vecLen=x->n; 894 906 895 PS_CONVERT_VECTOR_F32(w, myW);896 PS_CONVERT_VECTOR_F32(x, myX);897 PS_CONVERT_VECTOR_F32(y, myY);898 PS_CONVERT_VECTOR_F32(z, myZ);899 907 vecLen=w->n; 900 908 if (y->n < vecLen) { … … 939 947 psPolynomialType type) 940 948 { 949 PS_INT_CHECK_NON_NEGATIVE(n, NULL); 950 941 951 psS32 i = 0; 942 952 psDPolynomial1D* newPoly = NULL; … … 962 972 psPolynomialType type) 963 973 { 974 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 975 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 976 964 977 psS32 x = 0; 965 978 psS32 y = 0; … … 995 1008 psPolynomialType type) 996 1009 { 1010 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 1011 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 1012 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 1013 997 1014 psS32 x = 0; 998 1015 psS32 y = 0; … … 1037 1054 psPolynomialType type) 1038 1055 { 1056 PS_INT_CHECK_NON_NEGATIVE(nW, NULL); 1057 PS_INT_CHECK_NON_NEGATIVE(nX, NULL); 1058 PS_INT_CHECK_NON_NEGATIVE(nY, NULL); 1059 PS_INT_CHECK_NON_NEGATIVE(nZ, NULL); 1060 1039 1061 psS32 w = 0; 1040 1062 psS32 x = 0; … … 1207 1229 double psDPolynomial1DEval(double x, const psDPolynomial1D* myPoly) 1208 1230 { 1231 PS_POLY_CHECK_NULL(myPoly, NAN); 1232 1209 1233 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1210 1234 return(p_psDOrdPolynomial1DEval(x, myPoly)); … … 1220 1244 const psDPolynomial1D *myPoly) 1221 1245 { 1246 PS_POLY_CHECK_NULL(myPoly, NULL); 1247 PS_VECTOR_CHECK_NULL(x, NULL); 1248 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1249 1222 1250 psVector *tmp; 1223 1251 psVector *myX; 1224 1252 psS32 i; 1225 1226 PS_CONVERT_VECTOR_F64(x, myX);1227 1253 1228 1254 tmp = psVectorAlloc(x->n, PS_TYPE_F64); … … 1297 1323 double psDPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly) 1298 1324 { 1325 PS_POLY_CHECK_NULL(myPoly, NAN); 1326 1299 1327 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1300 1328 return(p_psDOrdPolynomial2DEval(x, y, myPoly)); … … 1311 1339 const psDPolynomial2D *myPoly) 1312 1340 { 1341 PS_POLY_CHECK_NULL(myPoly, NULL); 1342 PS_VECTOR_CHECK_NULL(x, NULL); 1343 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1344 PS_VECTOR_CHECK_NULL(y, NULL); 1345 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1346 1313 1347 psVector *tmp; 1314 1348 psVector *myX; … … 1317 1351 psS32 vecLen=x->n; 1318 1352 1319 PS_CONVERT_VECTOR_F64(x, myX);1320 PS_CONVERT_VECTOR_F64(y, myY);1321 1353 vecLen=x->n; 1322 1354 if (y->n < vecLen) { … … 1413 1445 double psDPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly) 1414 1446 { 1447 PS_POLY_CHECK_NULL(myPoly, NAN); 1448 1415 1449 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1416 1450 return(p_psDOrdPolynomial3DEval(x, y, z, myPoly)); … … 1428 1462 const psDPolynomial3D *myPoly) 1429 1463 { 1464 PS_POLY_CHECK_NULL(myPoly, NULL); 1465 PS_VECTOR_CHECK_NULL(x, NULL); 1466 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1467 PS_VECTOR_CHECK_NULL(y, NULL); 1468 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1469 PS_VECTOR_CHECK_NULL(z, NULL); 1470 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F64, NULL); 1471 1430 1472 psVector *tmp; 1431 1473 psVector *myX; … … 1435 1477 psS32 vecLen=x->n; 1436 1478 1437 PS_CONVERT_VECTOR_F64(x, myX);1438 PS_CONVERT_VECTOR_F64(y, myY);1439 PS_CONVERT_VECTOR_F64(z, myZ);1440 1479 vecLen=x->n; 1441 1480 if (y->n < vecLen) { … … 1557 1596 double psDPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly) 1558 1597 { 1598 PS_POLY_CHECK_NULL(myPoly, NAN); 1599 1559 1600 if (myPoly->type == PS_POLYNOMIAL_ORD) { 1560 1601 return(p_psDOrdPolynomial4DEval(w,x,y,z, myPoly)); … … 1573 1614 const psDPolynomial4D *myPoly) 1574 1615 { 1616 PS_POLY_CHECK_NULL(myPoly, NULL); 1617 PS_VECTOR_CHECK_NULL(w, NULL); 1618 PS_VECTOR_CHECK_TYPE(w, PS_TYPE_F64, NULL); 1619 PS_VECTOR_CHECK_NULL(x, NULL); 1620 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 1621 PS_VECTOR_CHECK_NULL(y, NULL); 1622 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 1623 PS_VECTOR_CHECK_NULL(z, NULL); 1624 PS_VECTOR_CHECK_TYPE(z, PS_TYPE_F64, NULL); 1625 1575 1626 psVector *tmp; 1576 1627 psVector *myW; … … 1581 1632 psS32 vecLen=x->n; 1582 1633 1583 PS_CONVERT_VECTOR_F64(w, myW);1584 PS_CONVERT_VECTOR_F64(x, myX);1585 PS_CONVERT_VECTOR_F64(y, myY);1586 PS_CONVERT_VECTOR_F64(z, myZ);1587 1634 vecLen=w->n; 1588 1635 if (y->n < vecLen) { -
trunk/psLib/src/math/psStats.c
r2213 r2217 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.7 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-27 2 0:11:47$13 *11 * @version $Revision: 1.74 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-27 21:06:30 $ 13 n * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 15 */ … … 39 39 /* DEFINE STATEMENTS */ 40 40 /*****************************************************************************/ 41 // will use robust statistical methods. 42 #define GAUSS_WIDTH 5 // The width of the Gaussian or boxcar smoothing. 43 #define CLIPPED_NUM_ITER_LB 1 44 #define CLIPPED_NUM_ITER_UB 10 45 #define CLIPPED_SIGMA_LB 1.0 46 #define CLIPPED_SIGMA_UB 10.0 47 #define true 1 48 #define false 0 49 #define MY_MAX_FLOAT HUGE 50 #define MAX_ITERATIONS 10 51 52 void p_psVectorRobustStats(const psVector* restrict myVector, 53 const psVector* restrict maskVector, psU32 maskVal, psStats* stats); 54 55 41 #define PS_GAUSS_WIDTH 5 // The width of the Gaussian or boxcar smoothing. 42 #define PS_CLIPPED_NUM_ITER_LB 1 43 #define PS_CLIPPED_NUM_ITER_UB 10 44 #define PS_CLIPPED_SIGMA_LB 1.0 45 #define PS_CLIPPED_SIGMA_UB 10.0 46 #define PS_MAX_FLOAT HUGE 47 #define PS_POLY_MEDIAN_MAX_ITERATIONS 10 48 49 #define PS_BIN_MIDPOINT(HISTOGRAM, BIN_NUM) \ 50 (0.5 * (HISTOGRAM->bounds->data.F32[(BIN_NUM)] + HISTOGRAM->bounds->data.F32[(BIN_NUM)+1])) 56 51 /*****************************************************************************/ 57 52 /* TYPE DEFINITIONS */ … … 59 54 psVector* p_psConvertToF32(psVector* in); 60 55 56 void p_psVectorRobustStats(const psVector* restrict myVector, 57 const psVector* restrict maskVector, 58 psU32 maskVal, 59 psStats* stats); 61 60 /*****************************************************************************/ 62 61 /* GLOBAL VARIABLES */ … … 245 244 { 246 245 psS32 i = 0; // Loop index variable 247 float max = - MY_MAX_FLOAT; // The calculated maximum246 float max = -PS_MAX_FLOAT; // The calculated maximum 248 247 float rangeMin = 0.0; // Exclude data below this 249 248 float rangeMax = 0.0; // Exclude date above this … … 306 305 { 307 306 psS32 i = 0; // Loop index variable 308 float min = MY_MAX_FLOAT; // The calculated maximum307 float min = PS_MAX_FLOAT; // The calculated maximum 309 308 float rangeMin = 0.0; // Exclude data below this 310 309 float rangeMax = 0.0; // Exclude date above this … … 493 492 robustHistogram with a Gaussian of width sigma. 494 493 *****************************************************************************/ 495 #define GAUSS_WIDTH_OTHER 5.0496 494 psVector* p_psVectorSmoothHistGaussian(psHistogram* robustHistogram, 497 495 float sigma) … … 521 519 // warnings? 522 520 523 x.data.F32 = iMid - ( GAUSS_WIDTH * sigma);521 x.data.F32 = iMid - (PS_GAUSS_WIDTH * sigma); 524 522 if ((x.data.F32 >= firstBound) && (x.data.F32 <= lastBound)) { 525 523 jMin = p_psVectorBinDisect(robustHistogram->bounds, &x); … … 531 529 } 532 530 533 x.data.F32 = iMid + ( GAUSS_WIDTH * sigma);531 x.data.F32 = iMid + (PS_GAUSS_WIDTH * sigma); 534 532 if ((x.data.F32 >= firstBound) && (x.data.F32 <= lastBound)) { 535 533 jMax = p_psVectorBinDisect(robustHistogram->bounds, &x); … … 744 742 745 743 // Endure that stats->clipIter is within the proper range. 746 if (!(( CLIPPED_NUM_ITER_LB <= stats->clipIter) && (stats->clipIter <=CLIPPED_NUM_ITER_UB))) {744 if (!((PS_CLIPPED_NUM_ITER_LB <= stats->clipIter) && (stats->clipIter <= PS_CLIPPED_NUM_ITER_UB))) { 747 745 psAbort(__func__, "Unallowed value for clipIter (%d).\n", stats->clipIter); 748 746 } 749 747 // Endure that stats->clipSigma is within the proper range. 750 if (!(( CLIPPED_SIGMA_LB <= stats->clipSigma) && (stats->clipSigma <=CLIPPED_SIGMA_UB))) {748 if (!((PS_CLIPPED_SIGMA_LB <= stats->clipSigma) && (stats->clipSigma <= PS_CLIPPED_SIGMA_UB))) { 751 749 psAbort(__func__, "Unallowed value for clipSigma (%f).\n", stats->clipSigma); 752 750 } … … 996 994 // printf("p_ps1DPolyMedian(%f, %f, %f) \n", rangeLow, rangeHigh, getThisValue); 997 995 998 while (numIterations < MAX_ITERATIONS) {996 while (numIterations < PS_POLY_MEDIAN_MAX_ITERATIONS) { 999 997 midpoint = (rangeHigh + rangeLow) / 2.0; 1000 998 if (fabs(midpoint - oldMidpoint) <= FLT_EPSILON) { … … 1099 1097 return(tmpFloat); 1100 1098 } 1101 1102 #define PS_BIN_MIDPOINT(HISTOGRAM, BIN_NUM) \1103 (0.5 * (HISTOGRAM->bounds->data.F32[(BIN_NUM)] + HISTOGRAM->bounds->data.F32[(BIN_NUM)+1]))1104 1099 1105 1100 /******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.
