Changeset 1946
- Timestamp:
- Oct 3, 2004, 2:39:58 PM (22 years ago)
- Location:
- trunk/psLib/test/dataManip
- Files:
-
- 5 edited
-
tst_psFunc02.c (modified) (6 diffs)
-
tst_psFunc03.c (modified) (13 diffs)
-
tst_psFunc04.c (modified) (2 diffs)
-
tst_psFunc05.c (modified) (5 diffs)
-
tst_psFunc07.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psFunc02.c
r1811 r1946 1 1 /***************************************************************************** 2 2 This routine must ensure that the psSpline1DAlloc() function properly 3 allocates the spline data structure. 4 5 XXX: figure out the memory deallocator 3 allocates the spline data structure. It allocates both linear and cubic 4 splines with a variety of min/max ranges. 6 5 *****************************************************************************/ 7 6 #include <stdio.h> … … 11 10 #include "psFunctions.h" 12 11 13 #define N 10 12 #define N 4 13 #define LINEAR 1 14 #define CUBIC 3 14 15 15 16 int main() … … 18 19 int memLeaks=0; 19 20 int i; 20 //int currentId = psMemGetId();21 int currentId = psMemGetId(); 21 22 psSpline1D *tmpSpline; 22 23 … … 26 27 printPositiveTestHeader(stdout, 27 28 "psFunction functions", 28 "psSpline1DAlloc() ");29 30 tmpSpline = psSpline1DAlloc(N, 1, 1.0, 10.0);31 if (tmpSpline == NULL) { 32 printf("ERROR: Could not allocate psSpline1D data structure\n"); 33 testStatus = false; 34 } 35 if (tmpSpline->spline == NULL) { 36 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 37 testStatus = false; 38 } 39 40 if (tmpSpline->n != N) { 41 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 42 testStatus = false; 43 } 44 45 for (i=0;i<N;i++) { 46 if (tmpSpline->spline[i] == NULL) { 47 printf("ERROR: Could not allocate spline %d\n", i); 48 testStatus = false; 49 } 50 if ((tmpSpline->spline[i])->n != 2) {51 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 52 testStatus = false; 53 } 54 } 55 56 if (tmpSpline->domains == NULL) { 57 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 58 testStatus = false; 59 } 60 61 for (i=0;i<N+1;i++) { 62 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 63 } 64 65 p sFree(tmpSpline);66 psMemCheckCorruption(1); 67 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);68 if (0 != memLeaks) { 69 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 70 } 71 72 printFooter(stdout, 73 "psFunctions functions", 74 "psSpline1DAlloc() ",75 testStatus); 76 77 /****************************************************************************/ 78 /****************************************************************************/ 79 testStatus = true; 80 printPositiveTestHeader(stdout, 81 "psFunction functions", 82 "psSpline1DAlloc() ");83 84 tmpSpline = psSpline1DAlloc(N, 1, 1.0, 1.0);29 "psSpline1DAlloc(): linear, normal"); 30 31 tmpSpline = psSpline1DAlloc(N, LINEAR, 1.0, 10.0); 32 if (tmpSpline == NULL) { 33 printf("ERROR: Could not allocate psSpline1D data structure\n"); 34 testStatus = false; 35 } 36 if (tmpSpline->spline == NULL) { 37 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 38 testStatus = false; 39 } 40 41 if (tmpSpline->n != N) { 42 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 43 testStatus = false; 44 } 45 46 for (i=0;i<N;i++) { 47 if (tmpSpline->spline[i] == NULL) { 48 printf("ERROR: Could not allocate spline %d\n", i); 49 testStatus = false; 50 } 51 if ((tmpSpline->spline[i])->n != LINEAR+1) { 52 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 53 testStatus = false; 54 } 55 } 56 57 if (tmpSpline->domains == NULL) { 58 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 59 testStatus = false; 60 } 61 62 for (i=0;i<N+1;i++) { 63 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 64 } 65 66 p_psSpline1DFree(tmpSpline); 67 psMemCheckCorruption(1); 68 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 69 if (0 != memLeaks) { 70 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 71 } 72 73 printFooter(stdout, 74 "psFunctions functions", 75 "psSpline1DAlloc(): linear, normal", 76 testStatus); 77 78 /****************************************************************************/ 79 /****************************************************************************/ 80 testStatus = true; 81 printPositiveTestHeader(stdout, 82 "psFunction functions", 83 "psSpline1DAlloc(): linear, min/max are equal"); 84 85 tmpSpline = psSpline1DAlloc(N, LINEAR, 1.0, 1.0); 85 86 86 87 if (tmpSpline != NULL) { … … 89 90 } 90 91 91 p sFree(tmpSpline);92 psMemCheckCorruption(1); 93 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);94 if (0 != memLeaks) { 95 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 96 } 97 98 printFooter(stdout, 99 "psFunctions functions", 100 "psSpline1DAlloc() ",101 testStatus); 102 103 /****************************************************************************/ 104 /****************************************************************************/ 105 testStatus = true; 106 printPositiveTestHeader(stdout, 107 "psFunction functions", 108 "psSpline1DAlloc() ");109 110 tmpSpline = psSpline1DAlloc(N, 1, 1.0, -1.0);111 if (tmpSpline == NULL) { 112 printf("ERROR: Could not allocate psSpline1D data structure\n"); 113 testStatus = false; 114 } 115 if (tmpSpline->spline == NULL) { 116 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 117 testStatus = false; 118 } 119 120 if (tmpSpline->n != N) { 121 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 122 testStatus = false; 123 } 124 125 for (i=0;i<N;i++) { 126 if (tmpSpline->spline[i] == NULL) { 127 printf("ERROR: Could not allocate spline %d\n", i); 128 testStatus = false; 129 } 130 if ((tmpSpline->spline[i])->n != 2) {131 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 132 testStatus = false; 133 } 134 } 135 136 if (tmpSpline->domains == NULL) { 137 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 138 testStatus = false; 139 } 140 141 for (i=0;i<N+1;i++) { 142 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 143 } 144 145 p sFree(tmpSpline);146 psMemCheckCorruption(1); 147 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);148 if (0 != memLeaks) { 149 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 150 } 151 152 printFooter(stdout, 153 "psFunctions functions", 154 "psSpline1DAlloc() ",155 testStatus); 156 157 /****************************************************************************/ 158 /****************************************************************************/ 159 testStatus = true; 160 printPositiveTestHeader(stdout, 161 "psFunction functions", 162 "psSpline1DAlloc() ");163 164 tmpSpline = psSpline1DAlloc(N, 3, 1.0, 10.0);165 if (tmpSpline == NULL) { 166 printf("ERROR: Could not allocate psSpline1D data structure\n"); 167 testStatus = false; 168 } 169 if (tmpSpline->spline == NULL) { 170 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 171 testStatus = false; 172 } 173 174 if (tmpSpline->n != N) { 175 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 176 testStatus = false; 177 } 178 179 for (i=0;i<N;i++) { 180 if (tmpSpline->spline[i] == NULL) { 181 printf("ERROR: Could not allocate spline %d\n", i); 182 testStatus = false; 183 } 184 if ((tmpSpline->spline[i])->n != 4) {185 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 186 testStatus = false; 187 } 188 } 189 190 if (tmpSpline->domains == NULL) { 191 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 192 testStatus = false; 193 } 194 195 for (i=0;i<N+1;i++) { 196 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 197 } 198 199 p sFree(tmpSpline);200 psMemCheckCorruption(1); 201 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);202 if (0 != memLeaks) { 203 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 204 } 205 206 printFooter(stdout, 207 "psFunctions functions", 208 "psSpline1DAlloc() ",209 testStatus); 210 211 /****************************************************************************/ 212 /****************************************************************************/ 213 testStatus = true; 214 printPositiveTestHeader(stdout, 215 "psFunction functions", 216 "psSpline1DAlloc() ");217 218 tmpSpline = psSpline1DAlloc(N, 3, 1.0, 1.0);92 p_psSpline1DFree(tmpSpline); 93 psMemCheckCorruption(1); 94 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 95 if (0 != memLeaks) { 96 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 97 } 98 99 printFooter(stdout, 100 "psFunctions functions", 101 "psSpline1DAlloc(): linear, min/max are equal", 102 testStatus); 103 104 /****************************************************************************/ 105 /****************************************************************************/ 106 testStatus = true; 107 printPositiveTestHeader(stdout, 108 "psFunction functions", 109 "psSpline1DAlloc(): linear, min > max."); 110 111 tmpSpline = psSpline1DAlloc(N, LINEAR, 1.0, -1.0); 112 if (tmpSpline == NULL) { 113 printf("ERROR: Could not allocate psSpline1D data structure\n"); 114 testStatus = false; 115 } 116 if (tmpSpline->spline == NULL) { 117 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 118 testStatus = false; 119 } 120 121 if (tmpSpline->n != N) { 122 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 123 testStatus = false; 124 } 125 126 for (i=0;i<N;i++) { 127 if (tmpSpline->spline[i] == NULL) { 128 printf("ERROR: Could not allocate spline %d\n", i); 129 testStatus = false; 130 } 131 if ((tmpSpline->spline[i])->n != LINEAR+1) { 132 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 133 testStatus = false; 134 } 135 } 136 137 if (tmpSpline->domains == NULL) { 138 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 139 testStatus = false; 140 } 141 142 for (i=0;i<N+1;i++) { 143 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 144 } 145 146 p_psSpline1DFree(tmpSpline); 147 psMemCheckCorruption(1); 148 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 149 if (0 != memLeaks) { 150 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 151 } 152 153 printFooter(stdout, 154 "psFunctions functions", 155 "psSpline1DAlloc(): linear, min > max.", 156 testStatus); 157 158 /****************************************************************************/ 159 /****************************************************************************/ 160 testStatus = true; 161 printPositiveTestHeader(stdout, 162 "psFunction functions", 163 "psSpline1DAlloc(), cubic, normal"); 164 165 tmpSpline = psSpline1DAlloc(N, CUBIC, 1.0, 10.0); 166 if (tmpSpline == NULL) { 167 printf("ERROR: Could not allocate psSpline1D data structure\n"); 168 testStatus = false; 169 } 170 if (tmpSpline->spline == NULL) { 171 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 172 testStatus = false; 173 } 174 175 if (tmpSpline->n != N) { 176 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 177 testStatus = false; 178 } 179 180 for (i=0;i<N;i++) { 181 if (tmpSpline->spline[i] == NULL) { 182 printf("ERROR: Could not allocate spline %d\n", i); 183 testStatus = false; 184 } 185 if ((tmpSpline->spline[i])->n != CUBIC+1) { 186 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 187 testStatus = false; 188 } 189 } 190 191 if (tmpSpline->domains == NULL) { 192 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 193 testStatus = false; 194 } 195 196 for (i=0;i<N+1;i++) { 197 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 198 } 199 200 p_psSpline1DFree(tmpSpline); 201 psMemCheckCorruption(1); 202 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 203 if (0 != memLeaks) { 204 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 205 } 206 207 printFooter(stdout, 208 "psFunctions functions", 209 "psSpline1DAlloc(): cubic, normal", 210 testStatus); 211 212 /****************************************************************************/ 213 /****************************************************************************/ 214 testStatus = true; 215 printPositiveTestHeader(stdout, 216 "psFunction functions", 217 "psSpline1DAlloc(): cubic, min/max are equal"); 218 219 tmpSpline = psSpline1DAlloc(N, CUBIC, 1.0, 1.0); 219 220 220 221 if (tmpSpline != NULL) { … … 223 224 } 224 225 225 p sFree(tmpSpline);226 psMemCheckCorruption(1); 227 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);228 if (0 != memLeaks) { 229 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 230 } 231 232 printFooter(stdout, 233 "psFunctions functions", 234 "psSpline1DAlloc() ",235 testStatus); 236 237 /****************************************************************************/ 238 /****************************************************************************/ 239 testStatus = true; 240 printPositiveTestHeader(stdout, 241 "psFunction functions", 242 "psSpline1DAlloc() ");243 244 tmpSpline = psSpline1DAlloc(N, 3, 1.0, -1.0);245 if (tmpSpline == NULL) { 246 printf("ERROR: Could not allocate psSpline1D data structure\n"); 247 testStatus = false; 248 } 249 if (tmpSpline->spline == NULL) { 250 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 251 testStatus = false; 252 } 253 254 if (tmpSpline->n != N) { 255 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 256 testStatus = false; 257 } 258 259 for (i=0;i<N;i++) { 260 if (tmpSpline->spline[i] == NULL) { 261 printf("ERROR: Could not allocate spline %d\n", i); 262 testStatus = false; 263 } 264 if ((tmpSpline->spline[i])->n != 4) {265 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 266 testStatus = false; 267 } 268 } 269 270 if (tmpSpline->domains == NULL) { 271 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 272 testStatus = false; 273 } 274 275 for (i=0;i<N+1;i++) { 276 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 277 } 278 279 p sFree(tmpSpline);280 psMemCheckCorruption(1); 281 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);282 if (0 != memLeaks) { 283 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 284 } 285 286 printFooter(stdout, 287 "psFunctions functions", 288 "psSpline1DAlloc() ",226 p_psSpline1DFree(tmpSpline); 227 psMemCheckCorruption(1); 228 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 229 if (0 != memLeaks) { 230 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 231 } 232 233 printFooter(stdout, 234 "psFunctions functions", 235 "psSpline1DAlloc(): cubic, min/max are equal", 236 testStatus); 237 238 /****************************************************************************/ 239 /****************************************************************************/ 240 testStatus = true; 241 printPositiveTestHeader(stdout, 242 "psFunction functions", 243 "psSpline1DAlloc(): cubic, min > max."); 244 245 tmpSpline = psSpline1DAlloc(N, CUBIC, 1.0, -1.0); 246 if (tmpSpline == NULL) { 247 printf("ERROR: Could not allocate psSpline1D data structure\n"); 248 testStatus = false; 249 } 250 if (tmpSpline->spline == NULL) { 251 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 252 testStatus = false; 253 } 254 255 if (tmpSpline->n != N) { 256 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 257 testStatus = false; 258 } 259 260 for (i=0;i<N;i++) { 261 if (tmpSpline->spline[i] == NULL) { 262 printf("ERROR: Could not allocate spline %d\n", i); 263 testStatus = false; 264 } 265 if ((tmpSpline->spline[i])->n != CUBIC+1) { 266 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 267 testStatus = false; 268 } 269 } 270 271 if (tmpSpline->domains == NULL) { 272 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 273 testStatus = false; 274 } 275 276 for (i=0;i<N+1;i++) { 277 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 278 } 279 280 p_psSpline1DFree(tmpSpline); 281 psMemCheckCorruption(1); 282 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 283 if (0 != memLeaks) { 284 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 285 } 286 287 printFooter(stdout, 288 "psFunctions functions", 289 "psSpline1DAlloc(): cubic, min > max.", 289 290 testStatus); 290 291 -
trunk/psLib/test/dataManip/tst_psFunc03.c
r1811 r1946 3 3 allocates the spline data structure. 4 4 5 XXX: figure out the memory deallocator6 5 XXX: test bounds? 7 6 *****************************************************************************/ … … 13 12 14 13 #define N 10 14 #define LINEAR 1 15 #define CUBIC 3 15 16 16 17 int main() … … 19 20 int memLeaks=0; 20 21 int i; 21 //int currentId = psMemGetId();22 int currentId = psMemGetId(); 22 23 psSpline1D *tmpSpline; 23 24 psVector *bounds; … … 28 29 printPositiveTestHeader(stdout, 29 30 "psFunction functions", 30 "psSpline1DAlloc ()");31 "psSpline1DAllocGeneric(): linear"); 31 32 bounds = psVectorAlloc(N+1, PS_TYPE_F32); 32 33 for (i=0;i<N+1;i++) { … … 34 35 } 35 36 36 tmpSpline = psSpline1DAllocGeneric(bounds, 1);37 tmpSpline = psSpline1DAllocGeneric(bounds, LINEAR); 37 38 if (tmpSpline == NULL) { 38 39 printf("ERROR: Could not allocate psSpline1D data structure\n"); … … 54 55 testStatus = false; 55 56 } 56 if ((tmpSpline->spline[i])->n != 2) {57 if ((tmpSpline->spline[i])->n != LINEAR+1) { 57 58 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 58 59 testStatus = false; … … 71 72 } 72 73 73 psFree(tmpSpline); 74 p_psSpline1DFree(tmpSpline); 75 psFree(bounds); 74 76 psMemCheckCorruption(1); 75 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);77 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 76 78 if (0 != memLeaks) { 77 79 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); … … 80 82 printFooter(stdout, 81 83 "psFunctions functions", 82 "psSpline1DAlloc ()",84 "psSpline1DAllocGeneric(): linear", 83 85 testStatus); 84 86 /****************************************************************************/ … … 87 89 printPositiveTestHeader(stdout, 88 90 "psFunction functions", 89 "psSpline1DAlloc ()");91 "psSpline1DAllocGeneric(): cubic"); 90 92 bounds = psVectorAlloc(N+1, PS_TYPE_F32); 91 93 for (i=0;i<N+1;i++) { … … 93 95 } 94 96 95 tmpSpline = psSpline1DAllocGeneric(bounds, 3);97 tmpSpline = psSpline1DAllocGeneric(bounds, CUBIC); 96 98 if (tmpSpline == NULL) { 97 99 printf("ERROR: Could not allocate psSpline1D data structure\n"); … … 113 115 testStatus = false; 114 116 } 115 if ((tmpSpline->spline[i])->n != 4) {117 if ((tmpSpline->spline[i])->n != CUBIC+1) { 116 118 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 117 119 testStatus = false; … … 130 132 } 131 133 132 psFree(tmpSpline); 134 p_psSpline1DFree(tmpSpline); 135 psFree(bounds); 133 136 psMemCheckCorruption(1); 134 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);137 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 135 138 if (0 != memLeaks) { 136 139 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); … … 139 142 printFooter(stdout, 140 143 "psFunctions functions", 141 "psSpline1DAlloc ()",144 "psSpline1DAllocGeneric(): cubic", 142 145 testStatus); 143 146 -
trunk/psLib/test/dataManip/tst_psFunc04.c
r1861 r1946 24 24 float x; 25 25 float y; 26 //int currentId = psMemGetId();26 int currentId = psMemGetId(); 27 27 psSpline1D *tmpSpline; 28 28 psVector *data; 29 29 30 30 psTraceSetLevel(".", 0); 31 31 32 /****************************************************************************/ 32 33 /****************************************************************************/ … … 52 53 } 53 54 54 p sFree(tmpSpline);55 p_psSpline1DFree(tmpSpline); 55 56 psMemCheckCorruption(1); 56 // memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 57 psFree(data); 58 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 57 59 if (0 != memLeaks) { 58 60 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); -
trunk/psLib/test/dataManip/tst_psFunc05.c
r1861 r1946 1 1 /***************************************************************************** 2 This routine must ensure that the psSpline1DEval() function works 3 properly. It creates a spline with psSpline1DAlloc(), creates a set of 4 data values, sets the spline polynomials with psVectorFitSpline1D(), then 5 calls psSpline1DEval() on new data values and ensures that the results 2 This routine must ensure that the psSpline1DEvalVector() function works 3 properly. It creates a spline with psSpline1DAlloc(), (1-D functions 4 are used for the spline polynomials) creates a set of data values, sets 5 the spline polynomials with psVectorFitSpline1D(), then calls 6 psSpline1DEvalVector() on new data values and ensures that the results 6 7 are correct. 7 8 XXX: figure out the memory deallocator9 8 *****************************************************************************/ 10 9 #include <stdio.h> … … 14 13 #include "psMemory.h" 15 14 #include "psFunctions.h" 16 17 15 #define N 8 16 #define SPLINE_ORDER 1 18 17 19 18 int main() … … 22 21 int memLeaks=0; 23 22 int i; 24 //int currentId = psMemGetId();23 int currentId = psMemGetId(); 25 24 psSpline1D *tmpSpline; 26 25 psVector *data; … … 37 36 data = psVectorAlloc(N+1, PS_TYPE_F32); 38 37 x = psVectorAlloc(N+1, PS_TYPE_F32); 39 y = psVectorAlloc(N+1, PS_TYPE_F32); 40 tmpSpline = psSpline1DAlloc(N, 1, 1.0, 10.0); 38 tmpSpline = psSpline1DAlloc(N, SPLINE_ORDER, 1.0, 10.0); 41 39 42 40 for (i=0;i<N+1;i++) { … … 59 57 } 60 58 61 psFree(tmpSpline); 59 p_psSpline1DFree(tmpSpline); 60 61 psFree(x); 62 psFree(y); 63 psFree(data); 64 62 65 psMemCheckCorruption(1); 63 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);66 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 64 67 if (0 != memLeaks) { 65 68 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); -
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.
