IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6186


Ignore:
Timestamp:
Jan 23, 2006, 12:25:31 PM (20 years ago)
Author:
gusciora
Message:

Misc code cleaning

Location:
trunk/psLib/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psCoord.c

    r5841 r6186  
    1010*  @author GLG, MHPCC
    1111*
    12 *  @version $Revision: 1.99 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-12-24 00:33:13 $
     12*  @version $Revision: 1.100 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-01-23 22:25:31 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    925925        return(p_psPlaneTransformLinearInvert((psPlaneTransform *) in));
    926926    }
    927     PS_INT_COMPARE(1, nSamples, NULL);
     927    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(nSamples, 1, NULL);
    928928
    929929    // Ensure that the input transformation is symmetrical.
  • trunk/psLib/src/imageops/psImageStats.c

    r5841 r6186  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.86 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-12-24 00:33:17 $
     11 *  @version $Revision: 1.87 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-01-23 22:25:31 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    212212
    213213    return (scalingFactors);
    214 }
    215 
    216 // XXX: Use a static array of Chebyshev polynomials.
    217 psPolynomial1D **p_psCreateChebyshevPolys(psS32 maxChebyPoly)
    218 {
    219     PS_ASSERT_INT_POSITIVE(maxChebyPoly, NULL);
    220     psPolynomial1D **chebPolys = NULL;
    221     psS32 i = 0;
    222     psS32 j = 0;
    223 
    224     chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
    225     for (i = 0; i < maxChebyPoly; i++) {
    226         // XXX: verify this, poly nOrder/nTerms change.
    227         chebPolys[i] = psPolynomial1DAlloc(i, PS_POLYNOMIAL_ORD);
    228     }
    229 
    230     // Create the Chebyshev polynomials.
    231     // Polynomial i has i-th order.
    232     chebPolys[0]->coeff[0] = 1;
    233     chebPolys[1]->coeff[1] = 1;
    234     for (i = 2; i < maxChebyPoly; i++) {
    235         for (j = 0; j < (1 + chebPolys[i - 1]->nX); j++) {
    236             chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
    237         }
    238         for (j = 0; j < (1 + chebPolys[i - 2]->nX); j++) {
    239             chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    240         }
    241     }
    242 
    243     return (chebPolys);
    244214}
    245215
     
    302272    // Determine how many Chebyshev polynomials
    303273    // are needed, then create them.
    304     // XXX: recorde or verify the poly order/nterm change
     274    // XXX: record or verify the poly order/nterm change
    305275    maxChebyPoly = coeffs->nX;
    306276    if (coeffs->nY > coeffs->nX) {
  • trunk/psLib/src/math/psConstants.h

    r5588 r6186  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-11-23 23:54:43 $
     8 *  @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-01-23 22:25:31 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1414 *       called with complex expressions.
    1515 *
    16  *  XXX: All functions which use the PS_CHECK macros must be scrutinized so
     16 *  XXX: All functions which use the PS_ASSERT macros must be scrutinized so
    1717 *  that we ensure that an argument which is expected to be output is
    1818 *  psFree'ed before reurning NULL.
     
    2121 *  throw a psError if the CONDITION is true.  However, some throw the error
    2222 *  if the CONDITION is false.  This should be consistant.
    23  *
    24  *  XXX: rename all these with form PS_ASSERT_CONDITION().
    2523 *
    2624 */
     
    156154}
    157155
    158 // Produce an error if (NAME1 > NAME2)
    159 // XXX: Get rid of this, use above macros.
    160 #define PS_INT_COMPARE(NAME1, NAME2, RVAL) \
    161 if ((NAME1) > (NAME2)) { \
    162     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    163             "Error: (%s > %s) (%d %d).", \
    164             #NAME1, #NAME2, NAME1, NAME2); \
    165     return(RVAL); \
    166 }
    167 
    168 // Produce an error if ((NAME1 > NAME2)
    169 // XXX: Get rid of this, use above macros.
    170 #define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \
    171 if ((NAME1) > (NAME2)) { \
    172     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    173             "Error: (%s > %s) (%f %f)", \
    174             #NAME1, #NAME2, NAME1, NAME2); \
    175     return(RVAL); \
    176 }
    177 
    178156#define PS_ASSERT_FLOAT_NON_EQUAL(NAME1, NAME2, RVAL) \
    179157if (fabs((NAME2) - (NAME1)) < FLT_EPSILON) { \
  • trunk/psLib/src/math/psMinimizePolyFit.c

    r6185 r6186  
    1010 *  @author EAM, IfA
    1111 *
    12  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-01-23 20:44:29 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-01-23 22:25:31 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1616 *
    17  *  XXX: must follow coding name standards on local functions.
    18  *  XXX: put local functions in front.
    1917 *  XXX: For clip-fit functions, what should we do if the mask is NULL?
    20  *  XXX: Generate macros for
    21  * PS_ASSERT_VECTOR_TYPES_MATCH()
    22  * PS_ASSERT_VECTOR_SIZES_MATCH()
    23  *  They should have better error messages.
    2418 *
    2519 */
     
    4236/*****************************************************************************/
    4337
     38#define PS_VECTOR_GEN_CHEBY_INDEX(VEC, SIZE, TYPE) \
     39VEC = psVectorAlloc(SIZE, TYPE); \
     40if (TYPE == PS_TYPE_F64) { \
     41    for (psS32 i = 0 ; i < SIZE ; i++) { \
     42        VEC->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \
     43    }\
     44} else if (TYPE == PS_TYPE_F32){ \
     45    for (psS32 i = 0 ; i < SIZE ; i++) { \
     46        VEC->data.F32[i] = ((2.0 / ((psF32) (SIZE - 1))) * ((psF32) i)) - 1.0; \
     47    }\
     48}\
     49
    4450/*****************************************************************************/
    4551/* TYPE DEFINITIONS                                                          */
     
    5864/*****************************************************************************/
    5965
    60 /******************************************************************************
    61  ******************************************************************************
    62  Analytical 1-D fitting routines.
    63  ******************************************************************************
    64  *****************************************************************************/
    65 // XXX: Make this a general type conversion macro, or function
    66 #define PS_VECTOR_GEN_F64_FROM_F32(VECF64, VECF32) \
    67 VECF64 = psVectorAlloc(VECF32->n, PS_TYPE_F64); \
    68 for (psS32 i = 0 ; i < VECF32->n ; i++) { \
    69     VECF64->data.F64[i] = (psF64) VECF32->data.F32[i]; \
    70 } \
    71 
    72 // XXX: Consolidate these
    73 #define PS_VECTOR_GEN_CHEBY_INDEX(VECF64, SIZE) \
    74 VECF64 = psVectorAlloc(SIZE, PS_TYPE_F64); \
    75 for (psS32 i = 0 ; i < SIZE ; i++) { \
    76     VECF64->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \
    77 }\
    78 
    79 #define PS_VECTOR_GEN_CHEBY_INDEX_F64(VECF64, SIZE) \
    80 VECF64 = psVectorAlloc(SIZE, PS_TYPE_F64); \
    81 for (psS32 i = 0 ; i < SIZE ; i++) { \
    82     VECF64->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \
    83 }\
    84 
    85 #define PS_VECTOR_GEN_CHEBY_INDEX_F32(VECF32, SIZE) \
    86 VECF32 = psVectorAlloc(SIZE, PS_TYPE_F32); \
    87 for (psS32 i = 0 ; i < SIZE ; i++) { \
    88     VECF32->data.F32[i] = ((2.0 / ((psF32) (SIZE - 1))) * ((psF32) i)) - 1.0; \
    89 }\
    9066/******************************************************************************
    9167BuildSums1D(sums, x, polyOrder, sums): this routine calculates the powers of
     
    11389
    11490    xSum = 1.0;
    115     for (int i = 0; i < nSum; i++) {
     91    for (psS32 i = 0; i < nSum; i++) {
    11692        sums->data.F64[i] = xSum;
    11793        xSum *= x;
     
    148124
    149125    xSum = 1.0;
    150     for (int i = 0; i < nXsum; i++) {
     126    for (psS32 i = 0; i < nXsum; i++) {
    151127        ySum = xSum;
    152         for (int j = 0; j < nYsum; j++) {
     128        for (psS32 j = 0; j < nYsum; j++) {
    153129            sums->data.F64[i][j] = ySum;
    154130            ySum *= y;
    155131        }
    156132        xSum *= x;
    157     }
    158 
    159     if (0) {
    160         printf("--------------------- BuildSums2D(%.2f %.2f) ---------------------\n", x, y);
    161         for (int i = 0; i < nXsum; i++) {
    162             for (int j = 0; j < nYsum; j++) {
    163                 printf("(%.2f) ", sums->data.F64[i][j]);
    164             }
    165             printf("\n");
    166         }
    167133    }
    168134
     
    196162    if (sums == NULL) {
    197163        sums = (psF64 ***) psAlloc (nXsum*sizeof(psF64));
    198         for (int i = 0; i < nXsum; i++) {
     164        for (psS32 i = 0; i < nXsum; i++) {
    199165            sums[i] = (psF64 **) psAlloc (nYsum*sizeof(psF64));
    200             for (int j = 0; j < nYsum; j++) {
     166            for (psS32 j = 0; j < nYsum; j++) {
    201167                sums[i][j] = (psF64 *) psAlloc (nZsum*sizeof(psF64));
    202168            }
     
    207173    if (1) {
    208174        zSum = 1.0;
    209         for (int k = 0; k < nZsum; k++) {
     175        for (psS32 k = 0; k < nZsum; k++) {
    210176            ySum = zSum;
    211             for (int j = 0; j < nYsum; j++) {
     177            for (psS32 j = 0; j < nYsum; j++) {
    212178                xSum = ySum;
    213                 for (int i = 0; i < nXsum; i++) {
     179                for (psS32 i = 0; i < nXsum; i++) {
    214180                    sums[i][j][k] = xSum;
    215181                    xSum *= x;
     
    221187    } else {
    222188        xSum = 1.0;
    223         for (int i = 0; i < nXsum; i++) {
     189        for (psS32 i = 0; i < nXsum; i++) {
    224190            ySum = xSum;
    225             for (int j = 0; j < nYsum; j++) {
     191            for (psS32 j = 0; j < nYsum; j++) {
    226192                zSum = ySum;
    227                 for (int k = 0; k < nZsum; k++) {
     193                for (psS32 k = 0; k < nZsum; k++) {
    228194                    sums[i][j][k] = zSum;
    229195                    zSum *= z;
     
    240206/******************************************************************************
    241207    BuildSums4D(sums, x, y, z, t, nXterm, nYterm, nZterm, nTterm). equiv to
    242     BuildSums2D(). The result is returned as a double ****
     208    BuildSums2D(). The result is returned as a psF64 ****
    243209*****************************************************************************/
    244210static psF64 ****BuildSums4D(
     
    268234    if (sums == NULL) {
    269235        sums = (psF64 ****) psAlloc (nXsum*sizeof(psF64));
    270         for (int i = 0; i < nXsum; i++) {
     236        for (psS32 i = 0; i < nXsum; i++) {
    271237            sums[i] = (psF64 ***) psAlloc (nYsum*sizeof(psF64));
    272             for (int j = 0; j < nYsum; j++) {
     238            for (psS32 j = 0; j < nYsum; j++) {
    273239                sums[i][j] = (psF64 **) psAlloc (nZsum*sizeof(psF64));
    274                 for (int k = 0; k < nZsum; k++) {
     240                for (psS32 k = 0; k < nZsum; k++) {
    275241                    sums[i][j][k] = (psF64 *) psAlloc (nTsum*sizeof(psF64));
    276242                }
     
    281247
    282248    tSum = 1.0;
    283     for (int m = 0; m < nTsum; m++) {
     249    for (psS32 m = 0; m < nTsum; m++) {
    284250        zSum = tSum;
    285         for (int k = 0; k < nZsum; k++) {
     251        for (psS32 k = 0; k < nZsum; k++) {
    286252            ySum = zSum;
    287             for (int j = 0; j < nYsum; j++) {
     253            for (psS32 j = 0; j < nYsum; j++) {
    288254                xSum = ySum;
    289                 for (int i = 0; i < nXsum; i++) {
     255                for (psS32 i = 0; i < nXsum; i++) {
    290256                    sums[i][j][k][m] = xSum;
    291257                    xSum *= x;
     
    299265    return (sums);
    300266}
     267
     268/******************************************************************************
     269 ******************************************************************************
     270 Analytical 1-D fitting routines.
     271 ******************************************************************************
     272 *****************************************************************************/
     273
    301274
    302275/******************************************************************************
     
    356329        NUM_DATA = x->n;
    357330    }
    358     // XX: psTrace    printf("vectorFitPolynomial1DChebySlow(): NUM_DATA is %d\n", NUM_DATA);
    359 
    360     psPolynomial1D **chebPolys = createChebyshevPolys(NUM_POLY);
     331    // psTrace    printf("vectorFitPolynomial1DChebySlow(): NUM_DATA is %d\n", NUM_DATA);
     332
     333    psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(NUM_POLY);
    361334    if (0) {
    362335        for (psS32 j = 0; j < NUM_POLY; j++) {
     
    416389    }
    417390
    418     // GaussJordan version
    419391    if (0) {
    420         // does the solution in place
    421         // XXX: Check error codes!
    422         psGaussJordan (A, B);
    423 
    424         // the first nTerm entries in B correspond directly to the desired
    425         // polynomial coefficients.  this is only true for the 1D case
    426         for (psS32 k = 0; k < NUM_POLY; k++) {
    427             myPoly->coeff[k] = B->data.F64[k];
     392        // GaussJordan version
     393        if (false == psGaussJordan(A, B)) {
     394            psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.  Returning NULL.\n");
     395            psFree(myPoly);
     396            myPoly = NULL;
     397        } else {
     398            // the first nTerm entries in B correspond directly to the desired
     399            // polynomial coefficients.  this is only true for the 1D case
     400            for (psS32 k = 0; k < NUM_POLY; k++) {
     401                myPoly->coeff[k] = B->data.F64[k];
     402            }
    428403        }
    429404    } else {
     
    433408        psVector* coeffs = NULL;
    434409
     410        // XXX: Check return codes.
    435411        ALUD = psImageAlloc(NUM_POLY, NUM_POLY, PS_TYPE_F64);
    436412        ALUD = psMatrixLUD(ALUD, &outPerm, A);
     
    468444    the [-1:1] interval.
    469445 
    470 XXX: mask, maskValue, yErr are currently ignored.
     446    NOTE: mask, maskValue, yErr are ignored with this function.
    471447*****************************************************************************/
    472448static psPolynomial1D *vectorFitPolynomial1DChebyFast(
     
    501477    tmpScalar.type.type = PS_TYPE_F64;
    502478
    503     // XXX: These assignments appear too simple to warrant code and
     479    // These assignments appear too simple to warrant code and
    504480    // variable declarations.  I retain them here to maintain coherence
    505481    // with the NR code.
     
    538514            fScalar = p_psVectorInterpolate((psVector *) x, (psVector *) y,
    539515                                            3, &tmpScalar);
     516            if (fScalar == NULL) {
     517                psError(PS_ERR_UNKNOWN, false, "Could not perform vector interpolation.  Returning NULL.\n");
     518                psFree(myPoly)
     519                return(NULL);
     520            }
     521
    540522            f->data.F64[i] = fScalar->data.F64;
    541523            psFree(fScalar);
    542524        }
    543525
    544         psTrace(".psLib.dataManip.vectorFitPolynomial1DCheby", 6,
    545                 "(x, X, y, f(X)) is (%f, %f, %f, %f)\n",
     526        psTrace(__func__, 6, "(x, X, y, f(X)) is (%f, %f, %f, %f)\n",
    546527                x->data.F64[i], X, y->data.F64[i], f->data.F64[i]);
    547528    }
     
    551532
    552533    fac = 2.0/((psF32) n);
    553     // XXX: is this loop bound correct?
    554534    for (j=0;j<myPoly->nX+1;j++) {
    555535        sum = 0.0;
     
    573553PS_TYPE_F64.
    574554 *****************************************************************************/
    575 psPolynomial1D* VectorFitPolynomial1DOrd(
     555static psPolynomial1D* VectorFitPolynomial1DOrd(
    576556    psPolynomial1D* myPoly,
    577557    const psVector *mask,
     
    581561    const psVector *x)
    582562{
    583     psTrace(__func__, 4, "---- VectorFitPolynomial1DOrd() begin ----\n");
    584     // XXX: these ASSERTS are redundant.
     563    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
    585564    PS_ASSERT_POLY_NON_NULL(myPoly, NULL);
    586565    PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL);
     
    600579    }
    601580
    602     psImage*     A = NULL;
    603     psVector*    B = NULL;
     581    psImage* A = NULL;
     582    psVector* B = NULL;
    604583    psVector* xSums = NULL;
    605584    psS32 nTerm;
     
    607586    psF64 wt;
    608587
    609     if (psTraceGetLevel (__func__) >= 6) {
     588    if (psTraceGetLevel(__func__) >= 6) {
    610589        psTrace(__func__, 6, "VectorFitPolynomial1D()\n");
    611590        for (psS32 i = 0; i < f->n; i++) {
     
    627606    nOrder = nTerm - 1;
    628607
    629     A     = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
    630     B     = psVectorAlloc(nTerm, PS_TYPE_F64);
    631 
    632     //
     608    A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
     609    B = psVectorAlloc(nTerm, PS_TYPE_F64);
    633610    // Initialize data structures.
    634     // XXX: Use psLib function.
    635     //
    636     PS_VECTOR_SET_F64(B, 0.0);
    637     PS_IMAGE_SET_F64(A, 0.0);
     611    if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) {
     612        psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B.  Returning NULL.\n");
     613        psFree(myPoly);
     614        psFree(A);
     615        psFree(B);
     616        psTrace(__func__, 4, "---- %s() End ----\n", __func__);
     617        return(NULL);
     618    }
    638619
    639620    // xSums look like: 1, x, x^2, ... x^(2n+1)
     
    641622    // XXX EAM : use temp pointers eg vB = B->data.F64 to save redirects
    642623    // XXX EAM : this function is only valid for data vectors of F64
    643     for (int k = 0; k < f->n; k++) {
     624    for (psS32 k = 0; k < f->n; k++) {
    644625        if ((mask != NULL) && (mask->data.U8[k] && maskValue)) {
    645626            continue;
     
    657638            wt = (fErr->data.F64[k] == 0) ? 0.0 : 1.0 / PS_SQR(fErr->data.F64[k]);
    658639        }
    659         for (int i = 0; i < nTerm; i++) {
     640        for (psS32 i = 0; i < nTerm; i++) {
    660641            B->data.F64[i] += f->data.F64[k] * xSums->data.F64[i] * wt;
    661642        }
     
    663644        // we could skip half of the array and assign at the end
    664645        // we must handle masked orders
    665         for (int i = 0; i < nTerm; i++) {
    666             for (int j = 0; j < nTerm; j++) {
     646        for (psS32 i = 0; i < nTerm; i++) {
     647            for (psS32 j = 0; j < nTerm; j++) {
    667648                A->data.F64[i][j] += xSums->data.F64[i + j] * wt;
    668649            }
     
    670651    }
    671652
    672     // GaussJordan version
    673653    if (0) {
    674         // does the solution in place
    675         // XXX: Check error codes!
    676         psGaussJordan (A, B);
    677 
    678         // the first nTerm entries in B correspond directly to the desired
    679         // polynomial coefficients.  this is only true for the 1D case
    680         for (int k = 0; k < nTerm; k++) {
    681             myPoly->coeff[k] = B->data.F64[k];
    682         }
     654        // GaussJordan version
     655        if (false == psGaussJordan(A, B)) {
     656            psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.  Returning NULL.\n");
     657            psFree(myPoly);
     658            myPoly = NULL;
     659        } else {
     660            // the first nTerm entries in B correspond directly to the desired
     661            // polynomial coefficients.  this is only true for the 1D case
     662            for (psS32 k = 0; k < nTerm; k++) {
     663                myPoly->coeff[k] = B->data.F64[k];
     664            }
     665        }
     666
    683667    } else {
    684668        // LUD version of the fit
     
    687671        psVector* coeffs = NULL;
    688672
     673        // XXX: Check return codes.
    689674        ALUD = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
    690675        ALUD = psMatrixLUD(ALUD, &outPerm, A);
    691676        coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm);
    692         for (int k = 0; k < nTerm; k++) {
     677        for (psS32 k = 0; k < nTerm; k++) {
    693678            myPoly->coeff[k] = coeffs->data.F64[k];
    694679        }
     
    703688    psFree(xSums);
    704689
    705     psTrace(__func__, 4, "---- VectorFitPolynomial1DOrd() End ----\n");
     690    psTrace(__func__, 4, "---- %s() End ----\n", __func__);
    706691    return (myPoly);
    707692}
     
    713698Types F32 and F64 are supported, however, type F32 is done via vector
    714699conversion only.
    715  
    716 XXX: Put the asserts at the beginning.  Why is this not failing tests?
    717700 *****************************************************************************/
    718701psPolynomial1D *psVectorFitPolynomial1D(
     
    748731
    749732    if (f->type.type != PS_TYPE_F64) {
    750         PS_VECTOR_GEN_F64_FROM_F32(f64, f);
     733        f64 = psVectorCopy(NULL, f, PS_TYPE_F64);
    751734    } else {
    752735        f64 = (psVector *) f;
     
    755738    if (x != NULL) {
    756739        if (x->type.type != PS_TYPE_F64) {
    757             PS_VECTOR_GEN_F64_FROM_F32(x64, x);
     740            x64 = psVectorCopy(NULL, x, PS_TYPE_F64);
    758741        } else {
    759742            x64 = (psVector *) x;
     
    763746    if (fErr != NULL) {
    764747        if (fErr->type.type != PS_TYPE_F64) {
    765             PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);
     748            fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64);
    766749        } else {
    767750            fErr64 = (psVector *) fErr;
     
    784767        if (x == NULL) {
    785768            // If x==NULL, create an x64 vector with x values set to (-1:1).
    786             PS_VECTOR_GEN_CHEBY_INDEX(x64, f64->n);
     769            PS_VECTOR_GEN_CHEBY_INDEX(x64, f64->n, PS_TYPE_F64);
    787770        }
    788771
     
    850833        } else if (poly->type == PS_POLYNOMIAL_CHEB) {
    851834            if (f->type.type == PS_TYPE_F32) {
    852                 PS_VECTOR_GEN_CHEBY_INDEX_F32(x, f->n);
     835                PS_VECTOR_GEN_CHEBY_INDEX(x, f->n, PS_TYPE_F32);
    853836            } else if (f->type.type == PS_TYPE_F64) {
    854                 PS_VECTOR_GEN_CHEBY_INDEX_F64(x, f->n);
     837                PS_VECTOR_GEN_CHEBY_INDEX(x, f->n, PS_TYPE_F64);
    855838            }
    856839        } else {
    857             printf("XXX: error, bad poly type.\n");
     840            psError(PS_ERR_UNKNOWN, false, "Error, bad poly type.\n");
     841            return(NULL);
    858842        }
    859843    }
     
    885869
    886870    //
    887     for (int N = 0; N < stats->clipIter; N++) {
     871    for (psS32 N = 0; N < stats->clipIter; N++) {
    888872        psTrace(__func__, 6, "Loop iteration %d.  Calling psVectorFitPolynomial1D()\n");
    889         int Nkeep = 0;
     873        psS32 Nkeep = 0;
    890874        if (psTraceGetLevel(__func__) >= 6) {
    891875            if (mask != NULL) {
     
    897881        poly = psVectorFitPolynomial1D(poly, mask, maskValue, f, fErr, x);
    898882        if (poly == NULL) {
    899             printf("XXX: psVectorFitPolynomial1D() returned NULL: Generate error, free data.\n");
     883            psError(PS_ERR_UNKNOWN, true, "Could not fit polynomial.  Returning NULL.\n");
     884            if (xIn == NULL) {
     885                psFree(x);
     886            }
    900887            return(NULL);
    901888        }
    902889
    903         // XXX: Check error codes
    904890        fit = psPolynomial1DEvalVector(poly, x);
     891        if (fit == NULL) {
     892            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector().  Returning NULL.\n");
     893            psFree(resid)
     894            return(NULL);
     895        }
    905896        for (psS32 i = 0 ; i < f->n ; i++) {
    906897            if (f->type.type == PS_TYPE_F64) {
     
    930921        // we are masking out any point which is out of range
    931922        // recovery is not allowed with this scheme
    932         for (int i = 0; i < resid->n; i++) {
     923        for (psS32 i = 0; i < resid->n; i++) {
    933924            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
    934925                continue;
     
    954945
    955946        //
    956         // XXX: We should probably exit this loop if no new elements were masked
     947        // We should probably exit this loop if no new elements were masked
    957948        // since the polynomial fit won't change.
    958949        //
     
    984975pairs.  All non-NULL vectors must be of type PS_TYPE_F64.
    985976 
    986 // XXX: What about the maskValue?
    987977 *****************************************************************************/
    988 psPolynomial2D* VectorFitPolynomial2DOrd(
     978static psPolynomial2D* VectorFitPolynomial2DOrd(
    989979    psPolynomial2D* myPoly,
    990980    const psVector* mask,
     
    995985    const psVector *y)
    996986{
    997     psTrace(__func__, 4, "---- VectorFitPolynomial2DOrd() begin ----\n");
    998     // These ASSERTS are redundant.
     987    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
    999988    PS_ASSERT_POLY_NON_NULL(myPoly, NULL);
    1000989    PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL);
     
    10251014    psS32 nTerm;
    10261015
    1027     // XXX:Watch for changes to the psPolys: nTerm != nOrder.
    10281016    psS32 nXterm = 1 + myPoly->nX;
    10291017    psS32 nYterm = 1 + myPoly->nY;
     
    10321020    A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
    10331021    B = psVectorAlloc(nTerm, PS_TYPE_F64);
    1034 
    1035     //
    10361022    // Initialize data structures.
    1037     // XXX: Use psLib function.
    1038     //
    1039     PS_VECTOR_SET_F64(B, 0.0);
    1040     PS_IMAGE_SET_F64(A, 0.0);
     1023    if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) {
     1024        psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B.  Returning NULL.\n");
     1025        psFree(myPoly);
     1026        psFree(A);
     1027        psFree(B);
     1028        psTrace(__func__, 4, "---- %s() End ----\n", __func__);
     1029        return(NULL);
     1030    }
    10411031
    10421032    // Sums look like: 1, x, x^2, ... x^(2n+1), y, xy, x^2y, ... x^(2n+1)
    10431033
    10441034    // Build the B and A data structs.
    1045     for (int k  = 0; k < x->n; k++) {
     1035    for (psS32 k  = 0; k < x->n; k++) {
    10461036        if ((mask != NULL) && (mask->data.U8[k] & maskValue)) {
    10471037            continue;
     
    10591049        // we could skip half of the array and assign at the end
    10601050        // we must handle masked orders
    1061         for (int n = 0; n < nXterm; n++) {
    1062             for (int m = 0; m < nYterm; m++) {
     1051        for (psS32 n = 0; n < nXterm; n++) {
     1052            for (psS32 m = 0; m < nYterm; m++) {
    10631053                B->data.F64[n+m*nXterm] += f->data.F64[k] * Sums->data.F64[n][m] * wt;
    10641054            }
    10651055        }
    10661056
    1067         for (int i = 0; i < nXterm; i++) {
    1068             for (int j = 0; j < nYterm; j++) {
    1069                 for (int n = 0; n < nXterm; n++) {
    1070                     for (int m = 0; m < nYterm; m++) {
     1057        for (psS32 i = 0; i < nXterm; i++) {
     1058            for (psS32 j = 0; j < nYterm; j++) {
     1059                for (psS32 n = 0; n < nXterm; n++) {
     1060                    for (psS32 m = 0; m < nYterm; m++) {
    10711061                        A->data.F64[i+j*nXterm][n+m*nXterm] += Sums->data.F64[i+n][j+m] * wt;
    10721062                    }
     
    10761066    }
    10771067
    1078     // does the solution in place
    1079     // XXX: Check error codes!
    1080     psGaussJordan (A, B);
    1081 
    1082     // select the appropriate solution entries
    1083     for (int n = 0; n < nXterm; n++) {
    1084         for (int m = 0; m < nYterm; m++) {
    1085             myPoly->coeff[n][m] = B->data.F64[n+m*nXterm];
     1068    if (false == psGaussJordan(A, B)) {
     1069        psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.  Returning NULL.\n");
     1070        psFree(myPoly);
     1071        myPoly = NULL;
     1072    } else {
     1073        // select the appropriate solution entries
     1074        for (psS32 n = 0; n < nXterm; n++) {
     1075            for (psS32 m = 0; m < nYterm; m++) {
     1076                myPoly->coeff[n][m] = B->data.F64[n+m*nXterm];
     1077            }
    10861078        }
    10871079    }
     
    10911083    psFree(Sums);
    10921084
    1093     psTrace(__func__, 4, "---- VectorFitPolynomial2DOrd() end ----\n");
     1085    psTrace(__func__, 4, "---- %s() end ----\n", __func__);
    10941086    return (myPoly);
    10951087}
     
    11391131    //
    11401132    if (f->type.type != PS_TYPE_F64) {
    1141         PS_VECTOR_GEN_F64_FROM_F32(f64, f);
     1133        f64 = psVectorCopy(NULL, f, PS_TYPE_F64);
    11421134    } else {
    11431135        f64 = (psVector *) f;
     
    11451137
    11461138    if (x->type.type != PS_TYPE_F64) {
    1147         PS_VECTOR_GEN_F64_FROM_F32(x64, x);
     1139        x64 = psVectorCopy(NULL, x, PS_TYPE_F64);
    11481140    } else {
    11491141        x64 = (psVector *) x;
     
    11511143
    11521144    if (y->type.type != PS_TYPE_F64) {
    1153         PS_VECTOR_GEN_F64_FROM_F32(y64, y);
     1145        y64 = psVectorCopy(NULL, y, PS_TYPE_F64);
    11541146    } else {
    11551147        y64 = (psVector *) y;
     
    11611153    if (fErr != NULL) {
    11621154        if (fErr->type.type != PS_TYPE_F64) {
    1163             PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);
     1155            fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64);
    11641156        } else {
    11651157            fErr64 = (psVector *) fErr;
     
    12721264
    12731265    // clipping range defined by min and max and/or clipSigma
    1274     float minClipSigma;
    1275     float maxClipSigma;
     1266    psF32 minClipSigma;
     1267    psF32 maxClipSigma;
    12761268    if (isfinite(stats->max)) {
    12771269        maxClipSigma = fabs(stats->max);
     
    12941286    psTrace(__func__, 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma);
    12951287
    1296     for (int N = 0; N < stats->clipIter; N++) {
     1288    for (psS32 N = 0; N < stats->clipIter; N++) {
    12971289        psTrace(__func__, 6, "Loop iteration %d.  Calling psVectorFitPolynomial1D()\n");
    1298         int Nkeep = 0;
     1290        psS32 Nkeep = 0;
    12991291        if (psTraceGetLevel(__func__) >= 6) {
    13001292            if (mask != NULL) {
     
    13061298
    13071299        poly = psVectorFitPolynomial2D(poly, mask, maskValue, f, fErr, x, y);
    1308         // XXX: Check error codes
     1300        if (poly == NULL) {
     1301            psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data.  Returning NULL.\n");
     1302            psFree(resid)
     1303            return(NULL);
     1304        }
     1305
    13091306        psVector *fit = psPolynomial2DEvalVector(poly, x, y);
     1307        if (fit == NULL) {
     1308            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector().  Returning NULL.\n");
     1309            psFree(resid)
     1310            return(NULL);
     1311        }
    13101312
    13111313        for (psS32 i = 0 ; i < f->n ; i++) {
     
    13281330        }
    13291331
    1330         // XXX: Check error codes
    13311332        stats  = psVectorStats(stats, resid, NULL, mask, maskValue);
     1333        if (stats == NULL) {
     1334            psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector.  Returning NULL.\n");
     1335            psFree(resid)
     1336            psFree(fit)
     1337            return(NULL);
     1338        }
    13321339        psTrace(__func__, 6, "Median is %f\n", stats->sampleMedian);
    13331340        psTrace(__func__, 6, "Stdev is %f\n", stats->sampleStdev);
    1334         float minClipValue = -minClipSigma*stats->sampleStdev;
    1335         float maxClipValue = +maxClipSigma*stats->sampleStdev;
     1341        psF32 minClipValue = -minClipSigma*stats->sampleStdev;
     1342        psF32 maxClipValue = +maxClipSigma*stats->sampleStdev;
    13361343
    13371344        // set mask if pts are not valid
    13381345        // we are masking out any point which is out of range
    13391346        // recovery is not allowed with this scheme
    1340         for (int i = 0; i < resid->n; i++) {
     1347        for (psS32 i = 0; i < resid->n; i++) {
    13411348            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
    13421349                continue;
     
    13881395y, z)-(f) pairs.  All non-NULL vectors must be of type PS_TYPE_F64.
    13891396 
    1390 XXX: This routine needs to be written.  Currently, this is simply a shell.  We
    1391 can assume that all vectors have been converted to F64, that (f, x, y, z) are
    1392 non-null and F64.  fErr may be NULL, but will be F64 is not.
    13931397 *****************************************************************************/
    1394 psPolynomial3D* VectorFitPolynomial3DOrd(
     1398static psPolynomial3D* VectorFitPolynomial3DOrd(
    13951399    psPolynomial3D* myPoly,
    13961400    const psVector* mask,
     
    14021406    const psVector *z)
    14031407{
    1404     psTrace(__func__, 4, "---- VectorFitPolynomial3DOrd() begin ----\n");
    1405     // These ASSERTS are redundant.
     1408    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
    14061409    PS_ASSERT_POLY_NON_NULL(myPoly, NULL);
    14071410    PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL);
     
    14351438    psS32 nTerm;
    14361439
    1437     // XXX:Watch for changes to the psPolys: nTerm != nOrder.
    14381440    psS32 nXterm = 1 + myPoly->nX;
    14391441    psS32 nYterm = 1 + myPoly->nY;
     
    14431445    A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
    14441446    B = psVectorAlloc(nTerm, PS_TYPE_F64);
    1445 
    14461447    // Initialize data structures.
    1447     psVectorInit (B, 0.0);
    1448     psImageInit (A, 0.0);
     1448    if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) {
     1449        psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B.  Returning NULL.\n");
     1450        psFree(myPoly);
     1451        psFree(A);
     1452        psFree(B);
     1453        psTrace(__func__, 4, "---- %s() End ----\n", __func__);
     1454        return(NULL);
     1455    }
    14491456
    14501457    // Sums look like: 1, x, x^2, ... x^(2n+1), y, xy, x^2y, ... x^(2n+1)*y, ...
    14511458
    14521459    // Build the B and A data structs.
    1453     for (int k  = 0; k < x->n; k++) {
     1460    for (psS32 k  = 0; k < x->n; k++) {
    14541461        if ((mask != NULL) && (mask->data.U8[k] & maskValue)) {
    14551462            continue;
     
    14671474        // we could skip half of the array and assign at the end
    14681475        // we must handle masked orders
    1469         for (int ix = 0; ix < nXterm; ix++) {
    1470             for (int iy = 0; iy < nYterm; iy++) {
    1471                 for (int iz = 0; iz < nZterm; iz++) {
     1476        for (psS32 ix = 0; ix < nXterm; ix++) {
     1477            for (psS32 iy = 0; iy < nYterm; iy++) {
     1478                for (psS32 iz = 0; iz < nZterm; iz++) {
    14721479                    if (myPoly->mask[ix][iy][iz]) {
    14731480                        continue;
    14741481                    } else {
    1475                         int nx = ix + iy*nXterm + iz*nXterm*nYterm;
     1482                        psS32 nx = ix + iy*nXterm + iz*nXterm*nYterm;
    14761483                        B->data.F64[nx] += f->data.F64[k] * Sums[ix][iy][iz] * wt;
    14771484                    }
     
    14801487        }
    14811488
    1482         for (int ix = 0; ix < nXterm; ix++) {
    1483             for (int iy = 0; iy < nYterm; iy++) {
    1484                 for (int iz = 0; iz < nZterm; iz++) {
     1489        for (psS32 ix = 0; ix < nXterm; ix++) {
     1490            for (psS32 iy = 0; iy < nYterm; iy++) {
     1491                for (psS32 iz = 0; iz < nZterm; iz++) {
    14851492                    if (myPoly->mask[ix][iy][iz])
    14861493                        continue;
    1487                     int nx = ix+iy*nXterm+iz*nXterm*nYterm;
    1488                     for (int jx = 0; jx < nXterm; jx++) {
    1489                         for (int jy = 0; jy < nYterm; jy++) {
    1490                             for (int jz = 0; jz < nZterm; jz++) {
     1494                    psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm;
     1495                    for (psS32 jx = 0; jx < nXterm; jx++) {
     1496                        for (psS32 jy = 0; jy < nYterm; jy++) {
     1497                            for (psS32 jz = 0; jz < nZterm; jz++) {
    14911498                                if (myPoly->mask[jx][jy][jz])
    14921499                                    continue;
    1493                                 int ny = jx+jy*nXterm+jz*nXterm*nYterm;
     1500                                psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm;
    14941501                                A->data.F64[nx][ny] += Sums[ix+jx][iy+jy][iz+jz] * wt;
    14951502                            }
     
    15011508    }
    15021509
    1503     for (int ix = 0; ix < nXterm; ix++) {
    1504         for (int iy = 0; iy < nYterm; iy++) {
    1505             for (int iz = 0; iz < nZterm; iz++) {
     1510    for (psS32 ix = 0; ix < nXterm; ix++) {
     1511        for (psS32 iy = 0; iy < nYterm; iy++) {
     1512            for (psS32 iz = 0; iz < nZterm; iz++) {
    15061513                if (!myPoly->mask[ix][iy][iz])
    15071514                    continue;
    1508                 int nx = ix+iy*nXterm+iz*nXterm*nYterm;
     1515                psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm;
    15091516                B->data.F64[nx] = 0;
    1510                 for (int jx = 0; jx < nXterm; jx++) {
    1511                     for (int jy = 0; jy < nYterm; jy++) {
    1512                         for (int jz = 0; jz < nZterm; jz++) {
    1513                             int ny = jx+jy*nXterm+jz*nXterm*nYterm;
     1517                for (psS32 jx = 0; jx < nXterm; jx++) {
     1518                    for (psS32 jy = 0; jy < nYterm; jy++) {
     1519                        for (psS32 jz = 0; jz < nZterm; jz++) {
     1520                            psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm;
    15141521                            A->data.F64[nx][ny] = (nx == ny) ? 1 : 0;
    15151522                        }
     
    15231530        // does the solution in place
    15241531        // The matrices were overflowing, so I switched to LUD.
    1525         if (false == psGaussJordan (A, B)) {
     1532        if (false == psGaussJordan(A, B)) {
    15261533            psFree(A);
    15271534            psFree(B);
    15281535
    1529             for (int ix = 0; ix < 2*nXterm; ix++) {
    1530                 for (int iy = 0; iy < 2*nYterm; iy++) {
     1536            for (psS32 ix = 0; ix < 2*nXterm; ix++) {
     1537                for (psS32 iy = 0; iy < 2*nYterm; iy++) {
    15311538                    psFree(Sums[ix][iy]);
    15321539                }
     
    15381545        }
    15391546        // select the appropriate solution entries
    1540         for (int ix = 0; ix < nXterm; ix++) {
    1541             for (int iy = 0; iy < nYterm; iy++) {
    1542                 for (int iz = 0; iz < nZterm; iz++) {
    1543                     int nx = ix+iy*nXterm+iz*nXterm*nYterm;
     1547        for (psS32 ix = 0; ix < nXterm; ix++) {
     1548            for (psS32 iy = 0; iy < nYterm; iy++) {
     1549                for (psS32 iz = 0; iz < nZterm; iz++) {
     1550                    psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm;
    15441551                    myPoly->coeff[ix][iy][iz] = B->data.F64[nx];
    15451552                    myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]);
     
    15531560        psVector* coeffs = NULL;
    15541561
     1562        // XXX: Check return codes.
    15551563        ALUD = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
    15561564        ALUD = psMatrixLUD(ALUD, &outPerm, A);
     
    15581566
    15591567        // select the appropriate solution entries
    1560         for (int ix = 0; ix < nXterm; ix++) {
    1561             for (int iy = 0; iy < nYterm; iy++) {
    1562                 for (int iz = 0; iz < nZterm; iz++) {
    1563                     int nx = ix+iy*nXterm+iz*nXterm*nYterm;
     1568        for (psS32 ix = 0; ix < nXterm; ix++) {
     1569            for (psS32 iy = 0; iy < nYterm; iy++) {
     1570                for (psS32 iz = 0; iz < nZterm; iz++) {
     1571                    psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm;
    15641572                    myPoly->coeff[ix][iy][iz] = coeffs->data.F64[nx];
    15651573                    myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]);
     
    15751583    psFree(B);
    15761584
    1577     for (int ix = 0; ix < 2*nXterm; ix++) {
    1578         for (int iy = 0; iy < 2*nYterm; iy++) {
     1585    for (psS32 ix = 0; ix < 2*nXterm; ix++) {
     1586        for (psS32 iy = 0; iy < 2*nYterm; iy++) {
    15791587            psFree(Sums[ix][iy]);
    15801588        }
     
    15831591    psFree(Sums);
    15841592
    1585     psTrace(__func__, 4, "---- VectorFitPolynomial3DOrd() end ----\n");
     1593    psTrace(__func__, 4, "---- %s() end ----\n", __func__);
    15861594    return (myPoly);
    15871595}
     
    16211629    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
    16221630    PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);
    1623     //    PS_ASSERT_VECTOR_TYPE(x, f->type.type, NULL);
    16241631    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
    16251632    PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);
    1626     //    PS_ASSERT_VECTOR_TYPE(y, f->type.type, NULL);
    16271633    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
    16281634    PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL);
    1629     //    PS_ASSERT_VECTOR_TYPE(z, f->type.type, NULL);
    16301635    if (fErr != NULL) {
    16311636        PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL);
     
    16371642    //
    16381643    if (f->type.type != PS_TYPE_F64) {
    1639         PS_VECTOR_GEN_F64_FROM_F32(f64, f);
     1644        f64 = psVectorCopy(NULL, f, PS_TYPE_F64);
    16401645    } else {
    16411646        f64 = (psVector *) f;
    16421647    }
    16431648    if (x->type.type != PS_TYPE_F64) {
    1644         PS_VECTOR_GEN_F64_FROM_F32(x64, x);
     1649        x64 = psVectorCopy(NULL, x, PS_TYPE_F64);
    16451650    } else {
    16461651        x64 = (psVector *) x;
    16471652    }
    16481653    if (y->type.type != PS_TYPE_F64) {
    1649         PS_VECTOR_GEN_F64_FROM_F32(y64, y);
     1654        y64 = psVectorCopy(NULL, y, PS_TYPE_F64);
    16501655    } else {
    16511656        y64 = (psVector *) y;
     
    16531658
    16541659    if (z->type.type != PS_TYPE_F64) {
    1655         PS_VECTOR_GEN_F64_FROM_F32(z64, z);
     1660        z64 = psVectorCopy(NULL, z, PS_TYPE_F64);
    16561661    } else {
    16571662        z64 = (psVector *) z;
     
    16601665    if (fErr != NULL) {
    16611666        if (fErr->type.type != PS_TYPE_F64) {
    1662             PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);
     1667            fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64);
    16631668        } else {
    16641669            fErr64 = (psVector *) fErr;
     
    17881793
    17891794    // clipping range defined by min and max and/or clipSigma
    1790     float minClipSigma;
    1791     float maxClipSigma;
     1795    psF32 minClipSigma;
     1796    psF32 maxClipSigma;
    17921797    if (isfinite(stats->max)) {
    17931798        maxClipSigma = fabs(stats->max);
     
    18111816    psTrace(__func__, 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma);
    18121817
    1813     for (int N = 0; N < stats->clipIter; N++) {
     1818    for (psS32 N = 0; N < stats->clipIter; N++) {
    18141819        psTrace(__func__, 6, "Loop iteration %d.  Calling psVectorFitPolynomial1D()\n");
    1815         int Nkeep = 0;
     1820        psS32 Nkeep = 0;
    18161821        if (psTraceGetLevel(__func__) >= 6) {
    18171822            if (mask != NULL) {
     
    18231828
    18241829        poly = psVectorFitPolynomial3D(poly, mask, maskValue, f, fErr, x, y, z);
    1825         // XXX: Check error codes
     1830        if (poly == NULL) {
     1831            psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data.  Returning NULL.\n");
     1832            psFree(resid)
     1833            psFree(fit)
     1834            return(NULL);
     1835        }
    18261836        fit = psPolynomial3DEvalVector(poly, x, y, z);
     1837        if (fit == NULL) {
     1838            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector().  Returning NULL.\n");
     1839            psFree(resid)
     1840            return(NULL);
     1841        }
    18271842        for (psS32 i = 0 ; i < f->n ; i++) {
    18281843            if (f->type.type == PS_TYPE_F64) {
     
    18441859        }
    18451860
    1846         // XXX: Check error codes
    18471861        stats  = psVectorStats(stats, resid, NULL, mask, maskValue);
     1862        if (stats == NULL) {
     1863            psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector.  Returning NULL.\n");
     1864            psFree(resid)
     1865            psFree(fit)
     1866            return(NULL);
     1867        }
     1868
    18481869        psTrace(__func__, 6, "Median is %f\n", stats->sampleMedian);
    18491870        psTrace(__func__, 6, "Stdev is %f\n", stats->sampleStdev);
    1850         float minClipValue = -minClipSigma*stats->sampleStdev;
    1851         float maxClipValue = +maxClipSigma*stats->sampleStdev;
     1871        psF32 minClipValue = -minClipSigma*stats->sampleStdev;
     1872        psF32 maxClipValue = +maxClipSigma*stats->sampleStdev;
    18521873
    18531874        // set mask if pts are not valid
    18541875        // we are masking out any point which is out of range
    18551876        // recovery is not allowed with this scheme
    1856         for (int i = 0; i < resid->n; i++) {
     1877        for (psS32 i = 0; i < resid->n; i++) {
    18571878            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
    18581879                continue;
     
    19021923y, z, t)-(f) pairs.  All non-NULL vectors must be of type PS_TYPE_F64.
    19031924 
    1904 XXX: This routine needs to be written.  Currently, this is simply a shell.  We
    1905 can assume that all vectors have been converted to F64, that (f, x, y, z) are
    1906 non-null and F64.  fErr may be NULL, but will be F64 is not.
    19071925 *****************************************************************************/
    1908 psPolynomial4D* VectorFitPolynomial4DOrd(
     1926static psPolynomial4D* VectorFitPolynomial4DOrd(
    19091927    psPolynomial4D* myPoly,
    19101928    const psVector* mask,
     
    19181936{
    19191937    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
    1920     // These ASSERTS are redundant.
    19211938    PS_ASSERT_POLY_NON_NULL(myPoly, NULL);
    19221939    PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL);
     
    19541971    psS32 nTerm;
    19551972
    1956     // XXX:Watch for changes to the psPolys: nTerm != nOrder.
    19571973    psS32 nXterm = 1 + myPoly->nX;
    19581974    psS32 nYterm = 1 + myPoly->nY;
     
    19631979    A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
    19641980    B = psVectorAlloc(nTerm, PS_TYPE_F64);
    1965 
    19661981    // Initialize data structures.
    1967     psVectorInit (B, 0.0);
    1968     psImageInit (A, 0.0);
     1982    if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) {
     1983        psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B.  Returning NULL.\n");
     1984        psFree(myPoly);
     1985        psFree(A);
     1986        psFree(B);
     1987        psTrace(__func__, 4, "---- %s() End ----\n", __func__);
     1988        return(NULL);
     1989    }
    19691990
    19701991    // Sums look like: 1, x, x^2, ... x^(2n+1), y, xy, x^2y, ... x^(2n+1)*y, ...
    19711992
    19721993    // Build the B and A data structs.
    1973     for (int k  = 0; k < x->n; k++) {
     1994    for (psS32 k  = 0; k < x->n; k++) {
    19741995        if ((mask != NULL) && (mask->data.U8[k] & maskValue)) {
    19751996            continue;
     
    19872008        // we could skip half of the array and assign at the end
    19882009        // we must handle masked orders
    1989         for (int ix = 0; ix < nXterm; ix++) {
    1990             for (int iy = 0; iy < nYterm; iy++) {
    1991                 for (int iz = 0; iz < nZterm; iz++) {
    1992                     for (int it = 0; it < nTterm; it++) {
     2010        for (psS32 ix = 0; ix < nXterm; ix++) {
     2011            for (psS32 iy = 0; iy < nYterm; iy++) {
     2012                for (psS32 iz = 0; iz < nZterm; iz++) {
     2013                    for (psS32 it = 0; it < nTterm; it++) {
    19932014                        if (myPoly->mask[ix][iy][iz][it])
    19942015                            continue;
    1995                         int nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
     2016                        psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
    19962017                        B->data.F64[nx] += f->data.F64[k] * Sums[ix][iy][iz][it] * wt;
    19972018                    }
     
    20002021        }
    20012022
    2002         for (int ix = 0; ix < nXterm; ix++) {
    2003             for (int iy = 0; iy < nYterm; iy++) {
    2004                 for (int iz = 0; iz < nZterm; iz++) {
    2005                     for (int it = 0; it < nTterm; it++) {
     2023        for (psS32 ix = 0; ix < nXterm; ix++) {
     2024            for (psS32 iy = 0; iy < nYterm; iy++) {
     2025                for (psS32 iz = 0; iz < nZterm; iz++) {
     2026                    for (psS32 it = 0; it < nTterm; it++) {
    20062027                        if (myPoly->mask[ix][iy][iz][it])
    20072028                            continue;
    2008                         int nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
    2009                         for (int jx = 0; jx < nXterm; jx++) {
    2010                             for (int jy = 0; jy < nYterm; jy++) {
    2011                                 for (int jz = 0; jz < nZterm; jz++) {
    2012                                     for (int jt = 0; jt < nTterm; jt++) {
     2029                        psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
     2030                        for (psS32 jx = 0; jx < nXterm; jx++) {
     2031                            for (psS32 jy = 0; jy < nYterm; jy++) {
     2032                                for (psS32 jz = 0; jz < nZterm; jz++) {
     2033                                    for (psS32 jt = 0; jt < nTterm; jt++) {
    20132034                                        if (myPoly->mask[jx][jy][jz][jt])
    20142035                                            continue;
    2015                                         int ny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm;
     2036                                        psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm;
    20162037                                        A->data.F64[nx][ny]+= Sums[ix+jx][iy+jy][iz+jz][it+jt] * wt;
    20172038                                    }
     
    20252046    }
    20262047
    2027     for (int ix = 0; ix < nXterm; ix++) {
    2028         for (int iy = 0; iy < nYterm; iy++) {
    2029             for (int iz = 0; iz < nZterm; iz++) {
    2030                 for (int it = 0; it < nTterm; it++) {
     2048    for (psS32 ix = 0; ix < nXterm; ix++) {
     2049        for (psS32 iy = 0; iy < nYterm; iy++) {
     2050            for (psS32 iz = 0; iz < nZterm; iz++) {
     2051                for (psS32 it = 0; it < nTterm; it++) {
    20312052                    if (!myPoly->mask[ix][iy][iz][it])
    20322053                        continue;
    2033                     int nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
     2054                    psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
    20342055                    B->data.F64[nx] = 0;
    2035                     for (int jx = 0; jx < nXterm; jx++) {
    2036                         for (int jy = 0; jy < nYterm; jy++) {
    2037                             for (int jz = 0; jz < nZterm; jz++) {
    2038                                 for (int jt = 0; jt < nTterm; jt++) {
    2039                                     int ny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm;
     2056                    for (psS32 jx = 0; jx < nXterm; jx++) {
     2057                        for (psS32 jy = 0; jy < nYterm; jy++) {
     2058                            for (psS32 jz = 0; jz < nZterm; jz++) {
     2059                                for (psS32 jt = 0; jt < nTterm; jt++) {
     2060                                    psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm;
    20402061                                    A->data.F64[nx][ny] = (nx == ny) ? 1 : 0;
    20412062                                }
     
    20512072    if (0) {
    20522073        // does the solution in place
    2053         // XXX: The GaussJordan version was overflowing, so I'm using LUD.
     2074        // The GaussJordan version was overflowing, so I'm using LUD.
    20542075        if (false == psGaussJordan(A, B)) {
    20552076            psFree(A);
    20562077            psFree(B);
    2057             for (int ix = 0; ix < 2*nXterm; ix++) {
    2058                 for (int iy = 0; iy < 2*nYterm; iy++) {
    2059                     for (int iz = 0; iz < 2*nZterm; iz++) {
     2078            for (psS32 ix = 0; ix < 2*nXterm; ix++) {
     2079                for (psS32 iy = 0; iy < 2*nYterm; iy++) {
     2080                    for (psS32 iz = 0; iz < 2*nZterm; iz++) {
    20602081                        psFree(Sums[ix][iy][iz]);
    20612082                    }
     
    20702091
    20712092        // select the appropriate solution entries
    2072         for (int ix = 0; ix < nXterm; ix++) {
    2073             for (int iy = 0; iy < nYterm; iy++) {
    2074                 for (int iz = 0; iz < nZterm; iz++) {
    2075                     for (int it = 0; it < nTterm; it++) {
    2076                         int nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
     2093        for (psS32 ix = 0; ix < nXterm; ix++) {
     2094            for (psS32 iy = 0; iy < nYterm; iy++) {
     2095                for (psS32 iz = 0; iz < nZterm; iz++) {
     2096                    for (psS32 it = 0; it < nTterm; it++) {
     2097                        psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
    20772098                        myPoly->coeff[ix][iy][iz][it] = B->data.F64[nx];
    20782099                        myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]);
     
    20872108        psVector* coeffs = NULL;
    20882109
     2110        // XXX: Check return codes.
    20892111        ALUD = psImageAlloc(nTerm, nTerm, PS_TYPE_F64);
    20902112        ALUD = psMatrixLUD(ALUD, &outPerm, A);
     
    20922114
    20932115        // select the appropriate solution entries
    2094         for (int ix = 0; ix < nXterm; ix++) {
    2095             for (int iy = 0; iy < nYterm; iy++) {
    2096                 for (int iz = 0; iz < nZterm; iz++) {
    2097                     for (int it = 0; it < nTterm; it++) {
    2098                         int nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
     2116        for (psS32 ix = 0; ix < nXterm; ix++) {
     2117            for (psS32 iy = 0; iy < nYterm; iy++) {
     2118                for (psS32 iz = 0; iz < nZterm; iz++) {
     2119                    for (psS32 it = 0; it < nTterm; it++) {
     2120                        psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
    20992121                        myPoly->coeff[ix][iy][iz][it] = coeffs->data.F64[nx];
    21002122                        myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]);
     
    21132135    psFree(B);
    21142136
    2115     for (int ix = 0; ix < 2*nXterm; ix++) {
    2116         for (int iy = 0; iy < 2*nYterm; iy++) {
    2117             for (int iz = 0; iz < 2*nZterm; iz++) {
     2137    for (psS32 ix = 0; ix < 2*nXterm; ix++) {
     2138        for (psS32 iy = 0; iy < 2*nYterm; iy++) {
     2139            for (psS32 iz = 0; iz < 2*nZterm; iz++) {
    21182140                psFree(Sums[ix][iy][iz]);
    21192141            }
     
    21802202    //
    21812203    if (f->type.type != PS_TYPE_F64) {
    2182         PS_VECTOR_GEN_F64_FROM_F32(f64, f);
     2204        f64 = psVectorCopy(NULL, f, PS_TYPE_F64);
    21832205    } else {
    21842206        f64 = (psVector *) f;
    21852207    }
    21862208    if (x->type.type != PS_TYPE_F64) {
    2187         PS_VECTOR_GEN_F64_FROM_F32(x64, x);
     2209        x64 = psVectorCopy(NULL, x, PS_TYPE_F64);
    21882210    } else {
    21892211        x64 = (psVector *) x;
    21902212    }
    21912213    if (y->type.type != PS_TYPE_F64) {
    2192         PS_VECTOR_GEN_F64_FROM_F32(y64, y);
     2214        y64 = psVectorCopy(NULL, y, PS_TYPE_F64);
    21932215    } else {
    21942216        y64 = (psVector *) y;
    21952217    }
    21962218    if (z->type.type != PS_TYPE_F64) {
    2197         PS_VECTOR_GEN_F64_FROM_F32(z64, z);
     2219        z64 = psVectorCopy(NULL, z, PS_TYPE_F64);
    21982220    } else {
    21992221        z64 = (psVector *) z;
    22002222    }
    22012223    if (t->type.type != PS_TYPE_F64) {
    2202         PS_VECTOR_GEN_F64_FROM_F32(t64, t);
     2224        t64 = psVectorCopy(NULL, t, PS_TYPE_F64);
    22032225    } else {
    22042226        t64 = (psVector *) t;
     
    22092231    if (fErr != NULL) {
    22102232        if (fErr->type.type != PS_TYPE_F64) {
    2211             PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);
     2233            fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64);
    22122234        } else {
    22132235            fErr64 = (psVector *) fErr;
     
    23102332
    23112333
    2312 // XXX: Add F64 support.
    23132334psPolynomial4D *psVectorClipFitPolynomial4D(
    23142335    psPolynomial4D *poly,
     
    23562377
    23572378    // clipping range defined by min and max and/or clipSigma
    2358     float minClipSigma;
    2359     float maxClipSigma;
     2379    psF32 minClipSigma;
     2380    psF32 maxClipSigma;
    23602381    if (isfinite(stats->max)) {
    23612382        maxClipSigma = fabs(stats->max);
     
    23792400    psTrace(__func__, 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma);
    23802401
    2381     for (int N = 0; N < stats->clipIter; N++) {
     2402    for (psS32 N = 0; N < stats->clipIter; N++) {
    23822403        psTrace(__func__, 6, "Loop iteration %d.  Calling psVectorFitPolynomial1D()\n");
    2383         int Nkeep = 0;
     2404        psS32 Nkeep = 0;
    23842405        if (psTraceGetLevel(__func__) >= 6) {
    23852406            if (mask != NULL) {
     
    23912412
    23922413        poly = psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t);
    2393         // XXX: Check error codes
     2414        if (poly == NULL) {
     2415            psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data.  Returning NULL.\n");
     2416            psFree(resid)
     2417            psFree(fit)
     2418            return(NULL);
     2419        }
     2420
    23942421        fit = psPolynomial4DEvalVector (poly, x, y, z, t);
    2395         // XXX: This is coded differently for 1D, 2D.  Consolidate.
     2422        if (fit == NULL) {
     2423            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector().  Returning NULL.\n");
     2424            psFree(resid)
     2425            return(NULL);
     2426        }
    23962427        for (psS32 i = 0 ; i < f->n ; i++) {
    23972428            if (f->type.type == PS_TYPE_F64) {
     
    24012432            }
    24022433        }
    2403         // XXX: Check error codes
    24042434
    24052435        if (psTraceGetLevel(__func__) >= 6) {
     
    24142444        }
    24152445
    2416         // XXX: Check error codes
    24172446        stats  = psVectorStats (stats, resid, NULL, mask, maskValue);
     2447        if (stats == NULL) {
     2448            psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector.  Returning NULL.\n");
     2449            psFree(resid)
     2450            psFree(fit)
     2451            return(NULL);
     2452        }
    24182453        psTrace(__func__, 6, "Median is %f\n", stats->sampleMedian);
    24192454        psTrace(__func__, 6, "Stdev is %f\n", stats->sampleStdev);
    2420         float minClipValue = -minClipSigma*stats->sampleStdev;
    2421         float maxClipValue = +maxClipSigma*stats->sampleStdev;
     2455        psF32 minClipValue = -minClipSigma*stats->sampleStdev;
     2456        psF32 maxClipValue = +maxClipSigma*stats->sampleStdev;
    24222457
    24232458        // set mask if pts are not valid
    24242459        // we are masking out any point which is out of range
    24252460        // recovery is not allowed with this scheme
    2426         for (int i = 0; i < resid->n; i++) {
     2461        for (psS32 i = 0; i < resid->n; i++) {
    24272462            if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
    24282463                continue;
  • trunk/psLib/src/math/psMinimizePowell.c

    r6101 r6186  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2006-01-21 02:43:31 $
     11 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-01-23 22:25:31 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232/*****************************************************************************/
    3333/* DEFINE STATEMENTS                                                         */
    34 /*****************************************************************************/
    35 
    36 /*****************************************************************************/
    37 /* TYPE DEFINITIONS                                                          */
    38 /*****************************************************************************/
    39 
    40 /*****************************************************************************/
    41 /* GLOBAL VARIABLES                                                          */
    42 /* XXX: Do these conform to code standard?         */
    43 /*****************************************************************************/
    44 static psMinimizeChi2PowellFunc Chi2PowellFunc = NULL;
    45 static psVector *myValue;
    46 static psVector *myError;
    47 /*****************************************************************************/
    48 /* FILE STATIC VARIABLES                                                     */
    49 /*****************************************************************************/
    50 
    51 /*****************************************************************************/
    52 /* FUNCTION IMPLEMENTATION - LOCAL                                           */
    5334/*****************************************************************************/
    5435
     
    8263} \
    8364
     65/*****************************************************************************/
     66/* TYPE DEFINITIONS                                                          */
     67/*****************************************************************************/
     68
     69/*****************************************************************************/
     70/* GLOBAL VARIABLES                                                          */
     71/* XXX: Do these conform to code standard?         */
     72/*****************************************************************************/
     73static psMinimizeChi2PowellFunc Chi2PowellFunc = NULL;
     74static psVector *myValue;
     75static psVector *myError;
     76/*****************************************************************************/
     77/* FILE STATIC VARIABLES                                                     */
     78/*****************************************************************************/
     79
     80/*****************************************************************************/
     81/* FUNCTION IMPLEMENTATION - LOCAL                                           */
     82/*****************************************************************************/
    8483
    8584/******************************************************************************
     
    402401    }
    403402
    404     // XXX:Use psTraceGetLevel()
    405     for (i=0;i<params->n;i++) {
    406         psTrace(__func__, 6,
    407                 "(params, paramMask, line)[%d] is (%f %d %f)\n", i,
    408                 params->data.F32[i],
    409                 paramMask->data.U8[i],
    410                 line->data.F32[i]);
     403    if (6 <= psTraceGetLevel(__func__)) {
     404        for (i=0;i<params->n;i++) {
     405            psTrace(__func__, 6, "(params, paramMask, line)[%d] is (%f %d %f)\n", i,
     406                    params->data.F32[i], paramMask->data.U8[i], line->data.F32[i]);
     407        }
    411408    }
    412409
  • trunk/psLib/src/math/psPolynomial.c

    r6101 r6186  
    77*  polynomials.  It also contains a Gaussian functions.
    88*
    9 *  @version $Revision: 1.135 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-01-21 02:43:31 $
     9*  @version $Revision: 1.136 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-01-23 22:25:31 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1414*  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
    1515*
    16 *  XXX: In the various polyAlloc(n) functions, n is really the order of the
    17 *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
    1816*/
    1917/*****************************************************************************/
     
    154152
    155153/*****************************************************************************
    156 createChebyshevPolys(n): this routine takes as input the required order n,
     154p_psCreateChebyshevPolys(n): this routine takes as input the required order n,
    157155and returns as output as a pointer to an array of n psPolynomial1D
    158156structures, corresponding to the first n Chebyshev polynomials.
     
    162160outer coefficients of the Chebyshev polynomials.
    163161 
    164 XXX: From the poly nOrder/nTerm changem the maxChebyPoly here is still nTerms,
    165 not nOrder.
    166162 *****************************************************************************/
    167 psPolynomial1D **createChebyshevPolys(psS32 numPolys)
     163psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys)
    168164{
    169165    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL);
     
    202198}
    203199
    204 /*
    205 static psPolynomial1D **createChebyshevPolysOld(psS32 maxChebyPoly)
    206 {
    207     PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);
    208  
    209     psPolynomial1D **chebPolys = NULL;
    210  
    211     chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
    212     for (psS32 i = 0; i < maxChebyPoly; i++) {
    213         chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
    214     }
    215  
    216     // Create the Chebyshev polynomials.
    217     // Polynomial i has i-th order.
    218     chebPolys[0]->coeff[0] = 1;
    219  
    220     // XXX: Bug 296
    221     if (maxChebyPoly > 1) {
    222         chebPolys[1]->coeff[1] = 1;
    223  
    224         for (psS32 i = 2; i < maxChebyPoly; i++) {
    225             for (psS32 j = 0; j < chebPolys[i - 1]->nX; j++) {
    226                 chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
    227             }
    228             for (psS32 j = 0; j < chebPolys[i - 2]->nX; j++) {
    229                 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    230             }
    231         }
    232     } else {
    233         // XXX: Code this.
    234         printf("WARNING: %u-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
    235     }
    236  
    237     return (chebPolys);
    238 }
    239 */
    240200
    241201/*****************************************************************************
    242202    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
    243203 *****************************************************************************/
    244 static psF64 ordPolynomial1DEval(psF64 x,
    245                                  const psPolynomial1D* poly)
     204static psF64 ordPolynomial1DEval(
     205    psF64 x,
     206    const psPolynomial1D* poly)
    246207{
    247208    unsigned int loop_x = 0;
     
    249210    psF64 xSum = 1.0;
    250211
    251     psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    252             "---- Calling ordPolynomial1DEval(%lf)\n", x);
    253     psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    254             "Polynomial order is %u\n", poly->nX);
     212    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
     213    psTrace(__func__, 4, "Polynomial order is %u\n", poly->nX);
    255214    for (loop_x = 0; loop_x < poly->nX+1; loop_x++) {
    256         psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    257                 "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]);
     215        psTrace(__func__, 4, "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]);
    258216    }
    259217
     
    262220            // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to
    263221            // 2 or higher in the test code, you get seg faults.
    264             psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 8,
     222            psTrace(__func__, 8,
    265223                    "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]);
    266224            polySum += xSum * poly->coeff[loop_x];
     
    269227    }
    270228
     229    psTrace(__func__, 4, "---- %s() end ----\n", __func__);
    271230    return(polySum);
    272231}
     
    284243    psVector *d;
    285244
    286     // XXX: n should be nTerms here (for clarity).  Or get rid of the variable.
    287245    unsigned int nTerms = 1 + poly->nX;
    288246    unsigned int i;
     
    338296    } else {
    339297        // This is old code that does not use Clenshaw's formula.  Get rid of it.
    340         psPolynomial1D **chebPolys = createChebyshevPolys(1 + poly->nX);
     298        psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX);
    341299
    342300        tmp = 0.0;
     
    402360        maxChebyPoly = poly->nY;
    403361    }
    404     chebPolys = createChebyshevPolys(maxChebyPoly + 1);
     362    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1);
    405363
    406364    for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) {
     
    476434        maxChebyPoly = poly->nZ;
    477435    }
    478     chebPolys = createChebyshevPolys(maxChebyPoly + 1);
     436    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1);
    479437
    480438    for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) {
     
    567525        maxChebyPoly = poly->nT;
    568526    }
    569     // XXX: Add 1 since createChebyshevPolys() takes nTerms, not nOrder.
    570     chebPolys = createChebyshevPolys(maxChebyPoly + 1);
     527    // Add 1 since p_psCreateChebyshevPolys() takes nTerms, not nOrder.
     528    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1);
    571529
    572530    for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) {
     
    648606/*****************************************************************************
    649607    This routine must allocate memory for the polynomial structures.
    650     XXX: replaces nterms variables with nOrder.  Lots of potential for bugs
    651          here.  Probably should create separately named private variables
    652          in these functions.
    653608 *****************************************************************************/
    654 psPolynomial1D* psPolynomial1DAlloc(unsigned int n,
    655                                     psPolynomialType type)
     609psPolynomial1D* psPolynomial1DAlloc(
     610    unsigned int n,
     611    psPolynomialType type)
    656612{
    657613    PS_ASSERT_INT_NONNEGATIVE(n, NULL);
    658 
    659     unsigned int i = 0;
    660     psPolynomial1D* newPoly = NULL;
    661 
    662     newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
     614    psU32 nOrder = n;
     615    psPolynomial1D *newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
    663616    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree);
    664617
    665618    newPoly->type = type;
    666     newPoly->nX = n;
     619    newPoly->nX = nOrder;
    667620    newPoly->p_min = NAN;
    668621    newPoly->p_max = NAN;
    669     newPoly->coeff = psAlloc((n + 1) * sizeof(psF64));
    670     newPoly->coeffErr = psAlloc((n + 1) * sizeof(psF64));
    671     newPoly->mask = (psMaskType *)psAlloc((n + 1) * sizeof(psMaskType));
    672     for (i = 0; i < (n + 1); i++) {
     622    newPoly->coeff = psAlloc((nOrder + 1) * sizeof(psF64));
     623    newPoly->coeffErr = psAlloc((nOrder + 1) * sizeof(psF64));
     624    newPoly->mask = (psMaskType *)psAlloc((nOrder + 1) * sizeof(psMaskType));
     625    for (psU32 i = 0; i < (nOrder + 1); i++) {
    673626        newPoly->coeff[i] = 0.0;
    674627        newPoly->coeffErr[i] = 0.0;
     
    967920// XXX: The output of this routine is always psF64 while 1D and 2D are
    968921// dependent on the input vectors.
    969 psVector *psPolynomial3DEvalVector(const psPolynomial3D *poly,
    970                                    const psVector *x,
    971                                    const psVector *y,
    972                                    const psVector *z)
    973 
     922psVector *psPolynomial3DEvalVector(
     923    const psPolynomial3D *poly,
     924    const psVector *x,
     925    const psVector *y,
     926    const psVector *z)
    974927{
    975928    PS_ASSERT_POLY_NON_NULL(poly, NULL);
     
    1036989}
    1037990
    1038 psF64 psPolynomial4DEval(const psPolynomial4D* poly,
    1039                          psF64 x,
    1040                          psF64 y,
    1041                          psF64 z,
    1042                          psF64 t)
     991psF64 psPolynomial4DEval(
     992    const psPolynomial4D* poly,
     993    psF64 x,
     994    psF64 y,
     995    psF64 z,
     996    psF64 t)
    1043997{
    1044998    PS_ASSERT_POLY_NON_NULL(poly, NAN);
     
    10561010}
    10571011
    1058 psVector *psPolynomial4DEvalVector(const psPolynomial4D *poly,
    1059                                    const psVector *x,
    1060                                    const psVector *y,
    1061                                    const psVector *z,
    1062                                    const psVector *t)
     1012psVector *psPolynomial4DEvalVector(
     1013    const psPolynomial4D *poly,
     1014    const psVector *x,
     1015    const psVector *y,
     1016    const psVector *z,
     1017    const psVector *t)
    10631018{
    10641019    PS_ASSERT_POLY_NON_NULL(poly, NULL);
  • trunk/psLib/src/math/psPolynomial.h

    r5813 r6186  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-12-19 23:58:47 $
     13 *  @version $Revision: 1.60 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-01-23 22:25:31 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6969psPolynomialType;
    7070
    71 // XXX: These are incorrect names for the order of the polynomial.  We
    72 // keep them here temporarily so we can later sed replace them with the
    73 // correct names.
    7471/** One-dimensional polynomial */
    7572typedef struct
     
    8582psPolynomial1D;
    8683
    87 // XXX: These are incorrect names for the order of the polynomial.  We
    88 // keep them here temporarily so we can later sed replace them with the
    89 // correct names.
    9084/** Two-dimensional polynomial */
    9185typedef struct
     
    10094psPolynomial2D;
    10195
    102 // XXX: These are incorrect names for the order of the polynomial.  We
    103 // keep them here temporarily so we can later sed replace them with the
    104 // correct names.
    10596/** Three-dimensional polynomial */
    10697typedef struct
     
    116107psPolynomial3D;
    117108
    118 // XXX: These are incorrect names for the order of the polynomial.  We
    119 // keep them here temporarily so we can later sed replace them with the
    120 // correct names.
    121109/** Four-dimensional polynomial */
    122110typedef struct
     
    301289
    302290
    303 // XXX: Coding Standard
    304 psPolynomial1D **createChebyshevPolys(psS32 numPolys);
     291
     292
     293/** Creates the specified number of chebyshev polys.
     294 *
     295 *  @return psPolynomial1D** The chebyshev polys.
     296 *
     297 */
     298psPolynomial1D **p_psCreateChebyshevPolys(
     299    psS32 numPolys
     300);
    305301
    306302typedef struct
  • trunk/psLib/src/math/psSpline.c

    r5517 r6186  
    77*  splines.
    88*
    9 *  @version $Revision: 1.132 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2005-11-15 20:10:32 $
     9*  @version $Revision: 1.133 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-01-23 22:25:31 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9090(F32).
    9191 
    92 XXX: This algorithm is derived from the Numerical Recipes.
    9392XXX: use recycled vectors for internal data.
    9493XXX: do an F64 version?
     
    111110    psF32 *Y = (psF32 *) & (y->data.F32[0]);
    112111    //
    113     // XXX: The second derivatives at the endpoints, undefined in the SDR,
     112    // The second derivatives at the endpoints, undefined in the SDR,
    114113    // are set in psConstants.h: PS_LEFT_SPLINE_DERIV, PS_RIGHT_SPLINE_DERIV.
    115114    //
     
    335334LaGrange interpolation.
    336335 *****************************************************************************/
    337 static psF32 interpolate1DF32(psF32 *domain,
    338                               psF32 *range,
    339                               unsigned int n,
    340                               unsigned int order,
    341                               psF32 x)
     336static psF32 interpolate1DF32(
     337    psF32 *domain,
     338    psF32 *range,
     339    unsigned int n,
     340    unsigned int order,
     341    psF32 x)
    342342{
    343343    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
  • trunk/psLib/src/math/psStats.c

    r6185 r6186  
    1717 *
    1818 *
    19  *  @version $Revision: 1.159 $ $Name: not supported by cvs2svn $
    20  *  @date $Date: 2006-01-23 20:44:29 $
     19 *  @version $Revision: 1.160 $ $Name: not supported by cvs2svn $
     20 *  @date $Date: 2006-01-23 22:25:31 $
    2121 *
    2222 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    23172317    psTrace(__func__, 5, "(lower, upper, n) is (%f, %f, %d)\n", lower, upper, n);
    23182318    PS_ASSERT_INT_POSITIVE(n, NULL);
    2319     PS_FLOAT_COMPARE(lower, upper, NULL);
     2319    PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(upper, lower, NULL);
    23202320
    23212321    psS32 i = 0;                  // Loop index variable
     
    23692369    PS_ASSERT_VECTOR_NON_NULL(bounds, NULL);
    23702370    PS_ASSERT_VECTOR_TYPE(bounds, PS_TYPE_F32, NULL);
    2371     PS_INT_COMPARE(2, bounds->n, NULL);
     2371    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(bounds->n, 2, NULL);
    23722372
    23732373    psHistogram* newHist = NULL;        // The new histogram structure
     
    24372437    PS_ASSERT_PTR_NON_NULL(out->nums, -1);
    24382438    PS_ASSERT_INT_WITHIN_RANGE(binNum, 0, ((out->nums->n)-1), -2);
    2439     PS_FLOAT_COMPARE(0.0, error, -3);
     2439    PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(error, 0.0, -3);
     2440
    24402441    PS_ASSERT_FLOAT_WITHIN_RANGE(data, out->bounds->data.F32[0], out->bounds->data.F32[(out->bounds->n)-1], -4);
    24412442
     
    27562757
    27572758    if ((stats->options & PS_STAT_USE_RANGE) && (stats->min >= stats->max)) {
    2758         PS_FLOAT_COMPARE(stats->min, stats->max, stats);
     2759        PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(stats->max, stats->min, stats);
    27592760    }
    27602761
Note: See TracChangeset for help on using the changeset viewer.