Changeset 1946 for trunk/psLib/test/dataManip/tst_psFunc07.c
- Timestamp:
- Oct 3, 2004, 2:39:58 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psFunc07.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psFunc07.c
r1902 r1946 4 4 values, sets the spline polynomials with psVectorFitSpline1D(), then calls 5 5 psSpline1DEval() on new data values and ensures that the results are correct. 6 7 XXX: figure out the memory deallocator8 9 XXX: Remove NR code.10 6 *****************************************************************************/ 11 7 #include <stdio.h> … … 16 12 #include "psFunctions.h" 17 13 18 #define NUM_SPLINES 20014 #define NUM_SPLINES 5 19 15 #define A 4.0 20 16 #define B -3.0 … … 30 26 } 31 27 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 else83 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 92 28 int main() 93 29 { 94 30 int testStatus = true; 95 31 int memLeaks=0; 32 int currentId = psMemGetId(); 96 33 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; 103 39 float NRX[NUM_SPLINES+2]; 104 40 float NRY[NUM_SPLINES+2]; … … 128 64 newX->data.F32[NUM_SPLINES] = x->data.F32[NUM_SPLINES]; 129 65 /****************************************************************************/ 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 /****************************************************************************/158 66 /* psLib Code */ 159 67 /****************************************************************************/ 68 160 69 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 }164 70 newY = psSpline1DEvalVector(newX, tmpSpline); 165 71 … … 174 80 } 175 81 176 psFree(tmpSpline); 82 psFree(x); 83 psFree(newX); 84 psFree(y); 85 p_psSpline1DFree(tmpSpline); 86 psFree(newY); 87 177 88 psMemCheckCorruption(1); 178 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);89 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 179 90 if (0 != memLeaks) { 180 91 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
Note:
See TracChangeset
for help on using the changeset viewer.
