IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 26, 2023, 10:40:25 AM (3 years ago)
Author:
eugene
Message:

adding function to generate an empty spline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/psLib.20230123/src/math/psSpline.c

    r42324 r42326  
    7272 *****************************************************************************/
    7373
    74 static psF32 *calculateSecondDerivs(
     74void calculateSecondDerivs(
    7575    const psSpline1D *mySpline,
    7676    psF32 dyLower, // if not NAN, lower-bound 1st derivative is defined
     
    8282    psS32 n = mySpline->n; // n is the number of knots
    8383    psF32 *u   = (psF32 *) psAlloc(n * sizeof(psF32));
    84     psF32 *d2y = (psF32 *) psAlloc(n * sizeof(psF32));
    85     psF32 *X = mySpline->xKnots;
    86     psF32 *Y = mySpline->yKnots;
     84
     85    psF32 *X   = mySpline->xKnots;
     86    psF32 *Y   = mySpline->yKnots;
     87    psF32 *d2y = mySpline->d2yKnots;
    8788
    8889    if (isfinite(dyLower)) {
     
    120121    psFree(u);
    121122    psTrace("psLib.math", 4, "---- %s() end ----\n", __func__);
    122 
    123     return(d2y);
     123    return;
    124124}
    125125
     
    151151
    152152    return(tmpSpline);
     153}
     154
     155/** Create an empty 1D spline **/
     156psSpline1D *psSpline1DCreate(
     157    int nKnots)                 ///< number of knots
     158{
     159    psSpline1D *spline = psSpline1DAlloc();
     160    spline->n = nKnots; // number of knots
     161
     162    spline->xKnots   = (psF32 *) psAlloc( spline->n * sizeof(psF32));
     163    spline->yKnots   = (psF32 *) psAlloc( spline->n * sizeof(psF32));
     164    spline->d2yKnots = (psF32 *) psAlloc( spline->n * sizeof(psF32));
     165
     166    // x & y can both be F32 or F64. should knots be F64?
     167    for (psS32 i = 0 ; i < spline->n ; i++) {
     168        spline->xKnots[i]   = NAN;
     169        spline->yKnots[i]   = NAN;
     170        spline->d2yKnots[i] = NAN;
     171    }
     172    return(spline);
    153173}
    154174
     
    187207    PS_ASSERT_LONG_LARGER_THAN_OR_EQUAL(y->n, (long)2, NULL);
    188208
    189     psSpline1D *spline = psSpline1DAlloc();
    190     spline->n = y->n; // number of knots
    191 
    192     spline->xKnots   = (psF32 *) psAlloc( spline->n * sizeof(psF32));
    193     spline->yKnots   = (psF32 *) psAlloc( spline->n * sizeof(psF32));
    194     spline->d2yKnots = (psF32 *) psAlloc( spline->n * sizeof(psF32));
     209    psSpline1D *spline = psSpline1DCreate(y->n);
    195210
    196211    // x & y can both be F32 or F64. should knots be F64?
     
    201216
    202217    // Generate the second derivatives at each data point.
    203     spline->d2yKnots = calculateSecondDerivs(spline, dyLower, dyUpper);
     218    calculateSecondDerivs(spline, dyLower, dyUpper);
    204219
    205220    psTrace("psLib.math", 3, "---- %s() end ----\n", __func__);
Note: See TracChangeset for help on using the changeset viewer.