IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1946


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

Added memory corruption checks to these files.

Location:
trunk/psLib/test/dataManip
Files:
5 edited

Legend:

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

    r1811 r1946  
    11/*****************************************************************************
    22    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.
    65 *****************************************************************************/
    76#include <stdio.h>
     
    1110#include "psFunctions.h"
    1211
    13 #define N 10
     12#define N 4
     13#define LINEAR 1
     14#define CUBIC 3
    1415
    1516int main()
     
    1819    int memLeaks=0;
    1920    int i;
    20     //    int  currentId = psMemGetId();
     21    int  currentId = psMemGetId();
    2122    psSpline1D *tmpSpline;
    2223
     
    2627    printPositiveTestHeader(stdout,
    2728                            "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     psFree(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);
    8586
    8687    if (tmpSpline != NULL) {
     
    8990    }
    9091
    91     psFree(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     psFree(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     psFree(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);
    219220
    220221    if (tmpSpline != NULL) {
     
    223224    }
    224225
    225     psFree(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     psFree(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.",
    289290                testStatus);
    290291
  • trunk/psLib/test/dataManip/tst_psFunc03.c

    r1811 r1946  
    33    allocates the spline data structure.
    44 
    5     XXX: figure out the memory deallocator
    65    XXX: test bounds?
    76 *****************************************************************************/
     
    1312
    1413#define N 10
     14#define LINEAR 1
     15#define CUBIC 3
    1516
    1617int main()
     
    1920    int memLeaks=0;
    2021    int i;
    21     //    int  currentId = psMemGetId();
     22    int  currentId = psMemGetId();
    2223    psSpline1D *tmpSpline;
    2324    psVector *bounds;
     
    2829    printPositiveTestHeader(stdout,
    2930                            "psFunction functions",
    30                             "psSpline1DAlloc()");
     31                            "psSpline1DAllocGeneric(): linear");
    3132    bounds = psVectorAlloc(N+1, PS_TYPE_F32);
    3233    for (i=0;i<N+1;i++) {
     
    3435    }
    3536
    36     tmpSpline = psSpline1DAllocGeneric(bounds, 1);
     37    tmpSpline = psSpline1DAllocGeneric(bounds, LINEAR);
    3738    if (tmpSpline == NULL) {
    3839        printf("ERROR: Could not allocate psSpline1D data structure\n");
     
    5455            testStatus = false;
    5556        }
    56         if ((tmpSpline->spline[i])->n != 2) {
     57        if ((tmpSpline->spline[i])->n != LINEAR+1) {
    5758            printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n);
    5859            testStatus = false;
     
    7172    }
    7273
    73     psFree(tmpSpline);
     74    p_psSpline1DFree(tmpSpline);
     75    psFree(bounds);
    7476    psMemCheckCorruption(1);
    75     //    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     77    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
    7678    if (0 != memLeaks) {
    7779        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     
    8082    printFooter(stdout,
    8183                "psFunctions functions",
    82                 "psSpline1DAlloc()",
     84                "psSpline1DAllocGeneric(): linear",
    8385                testStatus);
    8486    /****************************************************************************/
     
    8789    printPositiveTestHeader(stdout,
    8890                            "psFunction functions",
    89                             "psSpline1DAlloc()");
     91                            "psSpline1DAllocGeneric(): cubic");
    9092    bounds = psVectorAlloc(N+1, PS_TYPE_F32);
    9193    for (i=0;i<N+1;i++) {
     
    9395    }
    9496
    95     tmpSpline = psSpline1DAllocGeneric(bounds, 3);
     97    tmpSpline = psSpline1DAllocGeneric(bounds, CUBIC);
    9698    if (tmpSpline == NULL) {
    9799        printf("ERROR: Could not allocate psSpline1D data structure\n");
     
    113115            testStatus = false;
    114116        }
    115         if ((tmpSpline->spline[i])->n != 4) {
     117        if ((tmpSpline->spline[i])->n != CUBIC+1) {
    116118            printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n);
    117119            testStatus = false;
     
    130132    }
    131133
    132     psFree(tmpSpline);
     134    p_psSpline1DFree(tmpSpline);
     135    psFree(bounds);
    133136    psMemCheckCorruption(1);
    134     //    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     137    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
    135138    if (0 != memLeaks) {
    136139        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     
    139142    printFooter(stdout,
    140143                "psFunctions functions",
    141                 "psSpline1DAlloc()",
     144                "psSpline1DAllocGeneric(): cubic",
    142145                testStatus);
    143146
  • trunk/psLib/test/dataManip/tst_psFunc04.c

    r1861 r1946  
    2424    float x;
    2525    float y;
    26     //    int  currentId = psMemGetId();
     26    int  currentId = psMemGetId();
    2727    psSpline1D *tmpSpline;
    2828    psVector *data;
    2929
    3030    psTraceSetLevel(".", 0);
     31
    3132    /****************************************************************************/
    3233    /****************************************************************************/
     
    5253    }
    5354
    54     psFree(tmpSpline);
     55    p_psSpline1DFree(tmpSpline);
    5556    psMemCheckCorruption(1);
    56     //    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     57    psFree(data);
     58    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
    5759    if (0 != memLeaks) {
    5860        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
  • trunk/psLib/test/dataManip/tst_psFunc05.c

    r1861 r1946  
    11/*****************************************************************************
    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
    67    are correct.
    7  
    8     XXX: figure out the memory deallocator
    98 *****************************************************************************/
    109#include <stdio.h>
     
    1413#include "psMemory.h"
    1514#include "psFunctions.h"
    16 
    1715#define N 8
     16#define SPLINE_ORDER 1
    1817
    1918int main()
     
    2221    int memLeaks=0;
    2322    int i;
    24     //    int  currentId = psMemGetId();
     23    int  currentId = psMemGetId();
    2524    psSpline1D *tmpSpline;
    2625    psVector *data;
     
    3736    data = psVectorAlloc(N+1, PS_TYPE_F32);
    3837    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);
    4139
    4240    for (i=0;i<N+1;i++) {
     
    5957    }
    6058
    61     psFree(tmpSpline);
     59    p_psSpline1DFree(tmpSpline);
     60
     61    psFree(x);
     62    psFree(y);
     63    psFree(data);
     64
    6265    psMemCheckCorruption(1);
    63     //    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     66    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
    6467    if (0 != memLeaks) {
    6568        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
  • 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.