IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1982


Ignore:
Timestamp:
Oct 6, 2004, 11:30:53 AM (22 years ago)
Author:
gusciora
Message:

Vector allocation code.

Location:
trunk/psLib
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psVector.h

    r1953 r1982  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-05 01:43:57 $
     13 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-10-06 21:30:52 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5959
    6060/*****************************************************************************/
     61
    6162
    6263/** Allocate a vector.
  • trunk/psLib/src/dataManip/psFunctions.c

    r1968 r1982  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-06 00:48:15 $
     9 *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-06 21:30:53 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    20742074    n = spline->n;
    20752075    binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x);
    2076     if (binNum == -1) {
     2076    if (binNum < 0) {
    20772077        psLogMsg(__func__, PS_LOG_WARN,
    20782078                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).",
  • trunk/psLib/src/dataManip/psMinimize.c

    r1964 r1982  
    77 *  fit a 1-D polynomial to a set of data points.
    88 *
    9  *  @author George Gusciora, MHPCC
     9 *  @author GLF, MHPCC
    1010 *
    11  *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-05 23:14:15 $
     11 *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-06 21:30:53 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    227227supplied, but does not equal the domains specified in mySpline?
    228228XXX: can psSpline be NULL?
     229 
     230XXX: reimplement this assuming that mySpline is NULL?
     231 
     232XXX: What happens if X is NULL, then an index vector is generated for X, but
     233that index vector lies outside the range vectors in mySpline?
    229234 *****************************************************************************/
    230235psSpline1D *psVectorFitSpline1D(psSpline1D *mySpline,              ///< The spline which will be generated.
     
    269274        CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static);
    270275    }
    271     PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x, y);
    272     PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr, y);
    273 
    274     if (y->n != (1 + mySpline->n)) {
     276    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x32, y32);
     277    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr32, y32);
     278
     279    if (y32->n != (1 + mySpline->n)) {
    275280        psError(__func__, "data size / spline size mismatch (%d %d)\n",
    276                 y->n, mySpline->n);
     281                y32->n, mySpline->n);
    277282        return(NULL);
    278283    }
     
    282287    if (2 == (mySpline->spline[0])->n) {
    283288        for (i=0;i<mySpline->n;i++) {
    284             slope = (y->data.F32[i+1] - y->data.F32[i]) /
     289            slope = (y32->data.F32[i+1] - y32->data.F32[i]) /
    285290                    (mySpline->domains[i+1] - mySpline->domains[i]);
    286             (mySpline->spline[i])->coeff[0] = y->data.F32[i] -
     291            (mySpline->spline[i])->coeff[0] = y32->data.F32[i] -
    287292                                              (slope * mySpline->domains[i]);
    288293
     
    307312    // If we get here, then we know these are cubic splines.  We first
    308313    // generate the second derivatives at each data point.
    309     mySpline->p_psDeriv2 = CalculateSecondDerivs(x, y);
    310     for (i=0;i<y->n;i++)
     314    mySpline->p_psDeriv2 = CalculateSecondDerivs(x32, y32);
     315    for (i=0;i<y32->n;i++)
    311316        psTrace(".psLib.dataManip.psVectorFitSpline1D", 6,
    312317                "Second deriv[%d] is %f\n", i, mySpline->p_psDeriv2[i]);
     
    316321    // and Numerical Recipes in C.
    317322    for (i=0;i<numSplines;i++) {
    318         H = x->data.F32[i+1] - x->data.F32[i];
     323        H = x32->data.F32[i+1] - x32->data.F32[i];
    319324        psTrace(".psLib.dataManip.psVectorFitSpline1D", 4,
    320325                "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
     
    323328        //
    324329        // From (1)
    325         (mySpline->spline[i])->coeff[0] = (y->data.F32[i] * x->data.F32[i+1]/H);
     330        (mySpline->spline[i])->coeff[0] = (y32->data.F32[i] * x32->data.F32[i+1]/H);
    326331        // From (2)
    327         ((mySpline->spline[i])->coeff[0])-= ((y->data.F32[i+1] * x->data.F32[i])/H);
     332        ((mySpline->spline[i])->coeff[0])-= ((y32->data.F32[i+1] * x32->data.F32[i])/H);
    328333        // From (3)
    329         tmp = (x->data.F32[i+1] * x->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);
    330         tmp-= (x->data.F32[i+1] / H);
     334        tmp = (x32->data.F32[i+1] * x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H);
     335        tmp-= (x32->data.F32[i+1] / H);
    331336        tmp*= (mySpline->p_psDeriv2)[i] * H * H / 6.0;
    332337        ((mySpline->spline[i])->coeff[0])+= tmp;
    333338        // From (4)
    334         tmp = -(x->data.F32[i] * x->data.F32[i] * x->data.F32[i]) / (H * H * H);
    335         tmp+= (x->data.F32[i] / H);
     339        tmp = -(x32->data.F32[i] * x32->data.F32[i] * x32->data.F32[i]) / (H * H * H);
     340        tmp+= (x32->data.F32[i] / H);
    336341        tmp*= (mySpline->p_psDeriv2)[i+1] * H * H / 6.0;
    337342        ((mySpline->spline[i])->coeff[0])+= tmp;
     
    341346        //
    342347        // From (1)
    343         (mySpline->spline[i])->coeff[1] = -(y->data.F32[i]) / H;
     348        (mySpline->spline[i])->coeff[1] = -(y32->data.F32[i]) / H;
    344349        // From (2)
    345         ((mySpline->spline[i])->coeff[1])+= (y->data.F32[i+1] / H);
     350        ((mySpline->spline[i])->coeff[1])+= (y32->data.F32[i+1] / H);
    346351        // From (3)
    347         tmp = -3.0 * (x->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);
     352        tmp = -3.0 * (x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H);
    348353        tmp+= (1.0 / H);
    349354        tmp*= ((mySpline->p_psDeriv2)[i]) * H * H / 6.0;
    350355        ((mySpline->spline[i])->coeff[1])+= tmp;
    351356        // From (4)
    352         tmp = 3.0 * (x->data.F32[i] * x->data.F32[i]) / (H * H * H);
     357        tmp = 3.0 * (x32->data.F32[i] * x32->data.F32[i]) / (H * H * H);
    353358        tmp-= (1.0 / H);
    354359        tmp*= ((mySpline->p_psDeriv2)[i+1]) * H * H / 6.0;
     
    359364        //
    360365        // From (3)
    361         (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x->data.F32[i+1] / (6.0 * H);
     366        (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x32->data.F32[i+1] / (6.0 * H);
    362367        // From (4)
    363         ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x->data.F32[i] / (6.0 * H));
     368        ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x32->data.F32[i] / (6.0 * H));
    364369
    365370        //
  • trunk/psLib/src/dataManip/psMinimize.h

    r1963 r1982  
    66 *  chi-squared minimization, and 1-D polynomial fitting routines.
    77 *
    8  *  @author George Gusciora, MHPCC
     8 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-10-05 22:47:21 $
     10 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-10-06 21:30:53 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/math/psMinimize.c

    r1964 r1982  
    77 *  fit a 1-D polynomial to a set of data points.
    88 *
    9  *  @author George Gusciora, MHPCC
     9 *  @author GLF, MHPCC
    1010 *
    11  *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-05 23:14:15 $
     11 *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-06 21:30:53 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    227227supplied, but does not equal the domains specified in mySpline?
    228228XXX: can psSpline be NULL?
     229 
     230XXX: reimplement this assuming that mySpline is NULL?
     231 
     232XXX: What happens if X is NULL, then an index vector is generated for X, but
     233that index vector lies outside the range vectors in mySpline?
    229234 *****************************************************************************/
    230235psSpline1D *psVectorFitSpline1D(psSpline1D *mySpline,              ///< The spline which will be generated.
     
    269274        CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static);
    270275    }
    271     PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x, y);
    272     PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr, y);
    273 
    274     if (y->n != (1 + mySpline->n)) {
     276    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x32, y32);
     277    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr32, y32);
     278
     279    if (y32->n != (1 + mySpline->n)) {
    275280        psError(__func__, "data size / spline size mismatch (%d %d)\n",
    276                 y->n, mySpline->n);
     281                y32->n, mySpline->n);
    277282        return(NULL);
    278283    }
     
    282287    if (2 == (mySpline->spline[0])->n) {
    283288        for (i=0;i<mySpline->n;i++) {
    284             slope = (y->data.F32[i+1] - y->data.F32[i]) /
     289            slope = (y32->data.F32[i+1] - y32->data.F32[i]) /
    285290                    (mySpline->domains[i+1] - mySpline->domains[i]);
    286             (mySpline->spline[i])->coeff[0] = y->data.F32[i] -
     291            (mySpline->spline[i])->coeff[0] = y32->data.F32[i] -
    287292                                              (slope * mySpline->domains[i]);
    288293
     
    307312    // If we get here, then we know these are cubic splines.  We first
    308313    // generate the second derivatives at each data point.
    309     mySpline->p_psDeriv2 = CalculateSecondDerivs(x, y);
    310     for (i=0;i<y->n;i++)
     314    mySpline->p_psDeriv2 = CalculateSecondDerivs(x32, y32);
     315    for (i=0;i<y32->n;i++)
    311316        psTrace(".psLib.dataManip.psVectorFitSpline1D", 6,
    312317                "Second deriv[%d] is %f\n", i, mySpline->p_psDeriv2[i]);
     
    316321    // and Numerical Recipes in C.
    317322    for (i=0;i<numSplines;i++) {
    318         H = x->data.F32[i+1] - x->data.F32[i];
     323        H = x32->data.F32[i+1] - x32->data.F32[i];
    319324        psTrace(".psLib.dataManip.psVectorFitSpline1D", 4,
    320325                "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
     
    323328        //
    324329        // From (1)
    325         (mySpline->spline[i])->coeff[0] = (y->data.F32[i] * x->data.F32[i+1]/H);
     330        (mySpline->spline[i])->coeff[0] = (y32->data.F32[i] * x32->data.F32[i+1]/H);
    326331        // From (2)
    327         ((mySpline->spline[i])->coeff[0])-= ((y->data.F32[i+1] * x->data.F32[i])/H);
     332        ((mySpline->spline[i])->coeff[0])-= ((y32->data.F32[i+1] * x32->data.F32[i])/H);
    328333        // From (3)
    329         tmp = (x->data.F32[i+1] * x->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);
    330         tmp-= (x->data.F32[i+1] / H);
     334        tmp = (x32->data.F32[i+1] * x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H);
     335        tmp-= (x32->data.F32[i+1] / H);
    331336        tmp*= (mySpline->p_psDeriv2)[i] * H * H / 6.0;
    332337        ((mySpline->spline[i])->coeff[0])+= tmp;
    333338        // From (4)
    334         tmp = -(x->data.F32[i] * x->data.F32[i] * x->data.F32[i]) / (H * H * H);
    335         tmp+= (x->data.F32[i] / H);
     339        tmp = -(x32->data.F32[i] * x32->data.F32[i] * x32->data.F32[i]) / (H * H * H);
     340        tmp+= (x32->data.F32[i] / H);
    336341        tmp*= (mySpline->p_psDeriv2)[i+1] * H * H / 6.0;
    337342        ((mySpline->spline[i])->coeff[0])+= tmp;
     
    341346        //
    342347        // From (1)
    343         (mySpline->spline[i])->coeff[1] = -(y->data.F32[i]) / H;
     348        (mySpline->spline[i])->coeff[1] = -(y32->data.F32[i]) / H;
    344349        // From (2)
    345         ((mySpline->spline[i])->coeff[1])+= (y->data.F32[i+1] / H);
     350        ((mySpline->spline[i])->coeff[1])+= (y32->data.F32[i+1] / H);
    346351        // From (3)
    347         tmp = -3.0 * (x->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);
     352        tmp = -3.0 * (x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H);
    348353        tmp+= (1.0 / H);
    349354        tmp*= ((mySpline->p_psDeriv2)[i]) * H * H / 6.0;
    350355        ((mySpline->spline[i])->coeff[1])+= tmp;
    351356        // From (4)
    352         tmp = 3.0 * (x->data.F32[i] * x->data.F32[i]) / (H * H * H);
     357        tmp = 3.0 * (x32->data.F32[i] * x32->data.F32[i]) / (H * H * H);
    353358        tmp-= (1.0 / H);
    354359        tmp*= ((mySpline->p_psDeriv2)[i+1]) * H * H / 6.0;
     
    359364        //
    360365        // From (3)
    361         (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x->data.F32[i+1] / (6.0 * H);
     366        (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x32->data.F32[i+1] / (6.0 * H);
    362367        // From (4)
    363         ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x->data.F32[i] / (6.0 * H));
     368        ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x32->data.F32[i] / (6.0 * H));
    364369
    365370        //
  • trunk/psLib/src/math/psMinimize.h

    r1963 r1982  
    66 *  chi-squared minimization, and 1-D polynomial fitting routines.
    77 *
    8  *  @author George Gusciora, MHPCC
     8 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-10-05 22:47:21 $
     10 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-10-06 21:30:53 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/math/psPolynomial.c

    r1968 r1982  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-06 00:48:15 $
     9 *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-06 21:30:53 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    20742074    n = spline->n;
    20752075    binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x);
    2076     if (binNum == -1) {
     2076    if (binNum < 0) {
    20772077        psLogMsg(__func__, PS_LOG_WARN,
    20782078                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).",
  • trunk/psLib/src/math/psSpline.c

    r1968 r1982  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-06 00:48:15 $
     9 *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-06 21:30:53 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    20742074    n = spline->n;
    20752075    binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x);
    2076     if (binNum == -1) {
     2076    if (binNum < 0) {
    20772077        psLogMsg(__func__, PS_LOG_WARN,
    20782078                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).",
  • trunk/psLib/src/mathtypes/psVector.h

    r1953 r1982  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-05 01:43:57 $
     13 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-10-06 21:30:52 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5959
    6060/*****************************************************************************/
     61
    6162
    6263/** Allocate a vector.
  • trunk/psLib/test/dataManip/tst_psFunc04.c

    r1946 r1982  
    1717#define N 8
    1818
    19 int main()
     19int t00()
    2020{
    2121    int testStatus = true;
     
    6868    return (!testStatus);
    6969}
     70
     71int t01()
     72{
     73    int testStatus = true;
     74    int memLeaks=0;
     75    int i;
     76    float x;
     77    float y;
     78    int  currentId = psMemGetId();
     79    psSpline1D *tmpSpline;
     80    psVector *data;
     81
     82    psTraceSetLevel(".", 0);
     83
     84    /****************************************************************************/
     85    /****************************************************************************/
     86    testStatus = true;
     87    printPositiveTestHeader(stdout,
     88                            "psFunction functions",
     89                            "psSpline1DAlloc()");
     90    data = psVectorAlloc(N+1, PS_TYPE_F32);
     91    tmpSpline = psSpline1DAlloc(N, 1, 1.0, 10.0);
     92
     93    for (i=0;i<N+1;i++) {
     94        data->data.F32[i] = tmpSpline->domains[i];
     95    }
     96    psVectorFitSpline1D(tmpSpline, data, data, NULL);
     97
     98    for (i=0;i<N+1;i++) {
     99        x = 0.5 + (float) i+1;
     100        y = psSpline1DEval(tmpSpline, x);
     101        if (fabs(x-y) > FLT_EPSILON) {
     102            printf("ERROR: f(%f) is %f\n", x, y);
     103            testStatus = true;
     104        }
     105    }
     106
     107    p_psSpline1DFree(tmpSpline);
     108    psMemCheckCorruption(1);
     109    psFree(data);
     110    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     111    if (0 != memLeaks) {
     112        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     113    }
     114
     115    printFooter(stdout,
     116                "psFunctions functions",
     117                "psSpline1DAlloc()",
     118                testStatus);
     119
     120    return (!testStatus);
     121}
     122
     123int main()
     124{
     125    t00();
     126    //    t01();
     127}
  • trunk/psLib/test/dataManip/tst_psFunc07.c

    r1946 r1982  
    1212#include "psFunctions.h"
    1313
    14 #define NUM_SPLINES 5
     14#define NUM_SPLINES 50
    1515#define A 4.0
    1616#define B -3.0
     
    2020#define MAX 30
    2121#define ERROR_TOLERANCE 0.10
     22#define OFFSET (NUM_SPLINES * ERROR_TOLERANCE)
    2223
    2324float myFunc(float x)
     
    2627}
    2728
    28 int main()
     29int t00()
    2930{
    3031    int testStatus = true;
     
    3738    psVector *y = NULL;
    3839    psVector *newY = NULL;
    39     float NRX[NUM_SPLINES+2];
    40     float NRY[NUM_SPLINES+2];
    41     //    float tmpY;
    42     //    float derivs[NUM_SPLINES+2];
    4340
    4441    psTraceSetLevel(".", 0);
     
    4643    /****************************************************************************/
    4744    testStatus = true;
    48     printPositiveTestHeader(stdout,
    49                             "psFunction functions",
    50                             "psSpline1DAlloc()");
    5145    x = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32);
    5246    newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32);
     
    5549
    5650    for (i=0;i<NUM_SPLINES+1;i++) {
    57         NRX[i+1] = x->data.F32[i] = tmpSpline->domains[i];
    58         NRY[i+1] = y->data.F32[i] = myFunc(x->data.F32[i]);
    59         //        printf("DATA: (x, y) is (%f, %f)\n", x->data.F32[i], y->data.F32[i]);
     51        x->data.F32[i] = tmpSpline->domains[i];
     52        y->data.F32[i] = myFunc(x->data.F32[i]);
    6053    }
     54
    6155    for (i=0;i<NUM_SPLINES;i++) {
    6256        newX->data.F32[i]= ((x->data.F32[i] + x->data.F32[i+1])/2.0);
     
    6660    /*   psLib Code      */
    6761    /****************************************************************************/
     62    printPositiveTestHeader(stdout,
     63                            "psFunction functions",
     64                            "psSpline1DAlloc()");
    6865
    6966    psVectorFitSpline1D(tmpSpline, x, y, NULL);
    7067    newY = psSpline1DEvalVector(newX, tmpSpline);
    7168
    72     for (i=0;i<NUM_SPLINES+1;i++) {
     69    for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) {
    7370        if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) {
    7471            printf("ERROR[%d]: f(%f) is %f.  Should be %f\n", i,
    7572                   newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i]));
    7673        }
    77         //        tmpY = p_psNRSpline1DEval(tmpSpline, x, y, newX->data.F32[i]);
    78         //        printf("HMMM: p_psNRSpline1DEval(%f) is %f.  Should be %f\n",
    79         //                newX->data.F32[i], tmpY, myFunc(newX->data.F32[i]));
    8074    }
    8175
     
    9993    return (!testStatus);
    10094}
     95
     96int t00()
     97{
     98    int testStatus = true;
     99    int memLeaks=0;
     100    int  currentId = psMemGetId();
     101    int i;
     102    psSpline1D *tmpSpline = NULL;
     103    psVector *x = NULL;
     104    psVector *newX = NULL;
     105    psVector *y = NULL;
     106    psVector *newY = NULL;
     107
     108    psTraceSetLevel(".", 0);
     109    /****************************************************************************/
     110    /****************************************************************************/
     111    testStatus = true;
     112    x = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32);
     113    newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32);
     114    y = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32);
     115    tmpSpline = psSpline1DAlloc(NUM_SPLINES, 3, MIN, MAX);
     116
     117    for (i=0;i<NUM_SPLINES+1;i++) {
     118        x->data.F32[i] = tmpSpline->domains[i];
     119        y->data.F32[i] = myFunc(x->data.F32[i]);
     120    }
     121
     122    for (i=0;i<NUM_SPLINES;i++) {
     123        newX->data.F32[i]= ((x->data.F32[i] + x->data.F32[i+1])/2.0);
     124    }
     125    newX->data.F32[NUM_SPLINES] = x->data.F32[NUM_SPLINES];
     126    /****************************************************************************/
     127    /*   psLib Code      */
     128    /****************************************************************************/
     129    printPositiveTestHeader(stdout,
     130                            "psFunction functions",
     131                            "psSpline1DAlloc()");
     132
     133    psVectorFitSpline1D(tmpSpline, x, y, NULL);
     134    newY = psSpline1DEvalVector(newX, tmpSpline);
     135
     136    for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) {
     137        if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) {
     138            printf("ERROR[%d]: f(%f) is %f.  Should be %f\n", i,
     139                   newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i]));
     140        }
     141    }
     142
     143    psFree(x);
     144    psFree(newX);
     145    psFree(y);
     146    p_psSpline1DFree(tmpSpline);
     147    psFree(newY);
     148
     149    psMemCheckCorruption(1);
     150    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     151    if (0 != memLeaks) {
     152        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     153    }
     154
     155    printFooter(stdout,
     156                "psFunctions functions",
     157                "psSpline1DAlloc()",
     158                testStatus);
     159
     160    return (!testStatus);
     161}
     162
     163int main()
     164{
     165    t00();
     166}
Note: See TracChangeset for help on using the changeset viewer.