IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Vector allocation code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.