IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 3, 2004, 2:39:58 PM (22 years ago)
Author:
gusciora
Message:

Added memory corruption checks to these files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psFunc07.c

    r1902 r1946  
    44values, sets the spline polynomials with psVectorFitSpline1D(), then calls
    55psSpline1DEval() on new data values and ensures that the results are correct.
    6  
    7 XXX: figure out the memory deallocator
    8  
    9 XXX: Remove NR code.
    106 *****************************************************************************/
    117#include <stdio.h>
     
    1612#include "psFunctions.h"
    1713
    18 #define NUM_SPLINES 200
     14#define NUM_SPLINES 5
    1915#define A 4.0
    2016#define B -3.0
     
    3026}
    3127
    32 /*****************************************************************************
    33 XXX: This is Numerical Recipes in C code.  Remove from distribution.
    34  *****************************************************************************/
    35 void spline(float *x, float *y, int n, float yp1, float ypn, float *y2)
    36 {
    37     int i,k;
    38     float p,qn,sig,un,u[NUM_SPLINES+1];
    39 
    40     if (yp1 > 0.99e30) {
    41         y2[1]=u[1]=0.0;
    42     } else {
    43         y2[1] = -0.5;
    44         u[1]=(3.0/(x[2]-x[1]))*((y[2]-y[1])/(x[2]-x[1])-yp1);
    45     }
    46 
    47     for (i=2;i<=n-1;i++) {
    48         sig=(x[i]-x[i-1])/(x[i+1]-x[i-1]);
    49         p=sig*y2[i-1]+2.0;
    50         y2[i]=(sig-1.0)/p;
    51         u[i]=(y[i+1]-y[i])/(x[i+1]-x[i]) - (y[i]-y[i-1])/(x[i]-x[i-1]);
    52         u[i]=(6.0*u[i]/(x[i+1]-x[i-1])-sig*u[i-1])/p;
    53     }
    54 
    55     if (ypn > 0.99e30) {
    56         qn=un=0.0;
    57     } else {
    58         qn=0.5;
    59         un=(3.0/(x[n]-x[n-1]))*(ypn-(y[n]-y[n-1])/(x[n]-x[n-1]));
    60     }
    61     y2[n]=(un-qn*u[n-1])/(qn*y2[n-1]+1.0);
    62 
    63     for (k=n-1;k>=1;k--) {
    64         y2[k]=y2[k]*y2[k+1]+u[k];
    65     }
    66 }
    67 
    68 /*****************************************************************************
    69 XXX: This is Numerical Recipes in C code.  Remove from distribution.
    70  *****************************************************************************/
    71 void splint(float xa[], float ya[], float y2a[], int n, float x, float *y)
    72 {
    73     int klo,khi,k;
    74     float h,b,a;
    75 
    76     klo=1;
    77     khi=n;
    78     while (khi-klo > 1) {
    79         k=(khi+klo) >> 1;
    80         if (xa[k] > x)
    81             khi=k;
    82         else
    83             klo=k;
    84     }
    85     h=xa[khi]-xa[klo];
    86     a=(xa[khi]-x)/h;
    87     b=(x-xa[klo])/h;
    88     *y=a*ya[klo]+b*ya[khi]+((a*a*a-a)*y2a[klo]+(b*b*b-b)*y2a[khi])*(h*h)/6.0;
    89 }
    90 
    91 
    9228int main()
    9329{
    9430    int testStatus = true;
    9531    int memLeaks=0;
     32    int  currentId = psMemGetId();
    9633    int i;
    97     //    int  currentId = psMemGetId();
    98     psSpline1D *tmpSpline;
    99     psVector *x;
    100     psVector *newX;
    101     psVector *y;
    102     psVector *newY;
     34    psSpline1D *tmpSpline = NULL;
     35    psVector *x = NULL;
     36    psVector *newX = NULL;
     37    psVector *y = NULL;
     38    psVector *newY = NULL;
    10339    float NRX[NUM_SPLINES+2];
    10440    float NRY[NUM_SPLINES+2];
     
    12864    newX->data.F32[NUM_SPLINES] = x->data.F32[NUM_SPLINES];
    12965    /****************************************************************************/
    130     /*   NR Code       */
    131     /****************************************************************************/
    132     /*
    133         printf("========================== NR Code =========================\n");
    134         spline(&NRX[0],
    135                &NRY[0],
    136                NUM_SPLINES+1,
    137                0.0,
    138                0.0,
    139                &derivs[0]);
    140         for (i=1;i<=NUM_SPLINES+1;i++) {
    141             printf("NR: derivs[%d] is %f\n", i, derivs[i]);
    142         }
    143      
    144         for (i=1;i<=NUM_SPLINES+1;i++) {
    145             printf("===================================================\n");
    146             splint(&NRX[0],
    147                    &NRY[0],
    148                    &derivs[0],
    149                    NUM_SPLINES+1,
    150                    newX->data.F32[i-1],
    151                    &tmpY);
    152      
    153             printf("NR: p_psNRSpline1DEval(%f) is %f.  Should be %f\n",
    154                     newX->data.F32[i-1], tmpY, myFunc(newX->data.F32[i-1]));
    155         }
    156     */
    157     /****************************************************************************/
    15866    /*   psLib Code      */
    15967    /****************************************************************************/
     68
    16069    psVectorFitSpline1D(tmpSpline, x, y, NULL);
    161     for (i=0;i<NUM_SPLINES+1;i++) {
    162         //       printf("psLib: derivs[%d] is %f\n", i, tmpSpline->p_psDeriv2[i]);
    163     }
    16470    newY = psSpline1DEvalVector(newX, tmpSpline);
    16571
     
    17480    }
    17581
    176     psFree(tmpSpline);
     82    psFree(x);
     83    psFree(newX);
     84    psFree(y);
     85    p_psSpline1DFree(tmpSpline);
     86    psFree(newY);
     87
    17788    psMemCheckCorruption(1);
    178     //    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     89    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
    17990    if (0 != memLeaks) {
    18091        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
Note: See TracChangeset for help on using the changeset viewer.