src/numafunc1.c
l_int32
numaInterpolateEqxInterval(l_float32  startx,
                           l_float32  deltax,
                           NUMA      *nasy,
                           l_int32    type,
                           l_float32  x0,
                           l_float32  x1,
                           l_int32    npts,
                           NUMA     **pnax,
                           NUMA     **pnay)
{
l_int32     i, n;
l_float32   x, yval, maxx, delx;
NUMA       *nax, *nay;

    PROCNAME("numaInterpolateEqxInterval");

    if (pnax) *pnax = NULL;
    if (!pnay)
        return ERROR_INT("&nay not defined", procName, 1);
    *pnay = NULL;
    if (!nasy)
        return ERROR_INT("nasy not defined", procName, 1);
    if (deltax <= 0.0)
        return ERROR_INT("deltax not > 0", procName, 1);
    if (type != L_LINEAR_INTERP && type != L_QUADRATIC_INTERP)
        return ERROR_INT("invalid interp type", procName, 1);
    n = numaGetCount(nasy);
    if (type == L_QUADRATIC_INTERP && n == 2) {
        type = L_LINEAR_INTERP;
        L_WARNING("only 2 points; using linear interp", procName);
    }
    maxx = startx + deltax * (n - 1);
    if (x0 < startx || x1 > maxx || x1 <= x0)
        return ERROR_INT("[x0 ... x1] is not valid", procName, 1);
    if (npts < 3)
        return ERROR_INT("npts < 3", procName, 1);
    delx = (x1 - x0) / (l_float32)(npts - 1);  /* delx is for output nay */

    if ((nay = numaCreate(npts)) == NULL)
        return ERROR_INT("nay not made", procName, 1);
    numaSetXParameters(nay, x0, delx);
    *pnay = nay;
    if (pnax) {
        nax = numaCreate(npts);
        *pnax = nax;
    }

    for (i = 0; i < npts; i++) {
        x = x0 + i * delx;
        if (pnax)
            numaAddNumber(nax, x);
        numaInterpolateEqxVal(startx, deltax, nasy, type, x, &yval);
        numaAddNumber(nay, yval);
    }

    return 0;
}
/*!
 *  numaInterpolateEqxInterval()
 *
 *      Input:  startx (xval corresponding to first element in nas)
 *              deltax (x increment between array elements in nas)
 *              nasy  (numa of ordinate values, assumed equally spaced)
 *              type (L_LINEAR_INTERP, L_QUADRATIC_INTERP)
 *              x0 (start value of interval)
 *              x1 (end value of interval)
 *              npts (number of points to evaluate function in interval)
 *              &nax (<optional return> array of x values in interval)
 *              &nay (<return> array of y values in interval)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) Considering nasy as a function of x, the x values
 *          are equally spaced.
 *      (2) This creates nay (and optionally nax) of interpolated
 *          values over the specified interval (x0, x1).
 *      (3) If the interval (x0, x1) lies partially outside the array
 *          nasy (as interpreted by startx and deltax), it is an
 *          error and returns 1.
 *      (4) Note that deltax is the intrinsic x-increment for the input
 *          array nasy, whereas delx is the intrinsic x-increment for the
 *          output interpolated array nay.
 */


(1) Considering nasy as a function of x, the x values
are equally spaced.
(2) This creates nay (and optionally nax) of interpolated
values over the specified interval (x0, x1).
(3) If the interval (x0, x1) lies partially outside the array
nasy (as interpreted by startx and deltax), it is an
error and returns 1.
(4) Note that deltax is the intrinsic x-increment for the input
array nasy, whereas delx is the intrinsic x-increment for the
output interpolated array nay.
( 1 ) Considering nasy as a function of x the x values are equally spaced . ( 2 ) This creates nay ( and optionally nax ) of interpolated values over the specified interval ( x0 x1 ) . ( 3 ) If the interval ( x0 x1 ) lies partially outside the array nasy ( as interpreted by startx and deltax ) it is an error and returns 1 . ( 4 ) Note that deltax is the intrinsic x - increment for the input array nasy whereas delx is the intrinsic x - increment for the output interpolated array nay .
l_int32
numaInterpolateEqxInterval(l_float32  startx,
                           l_float32  deltax,
                           NUMA      *nasy,
                           l_int32    type,
                           l_float32  x0,
                           l_float32  x1,
                           l_int32    npts,
                           NUMA     **pnax,
                           NUMA     **pnay)
{
l_int32     i, n;
l_float32   x, yval, maxx, delx;
NUMA       *nax, *nay;
    PROCNAME("numaInterpolateEqxInterval");
    if (pnax) *pnax = NULL;
    if (!pnay)
        return ERROR_INT("&nay not defined", procName, 1);
    *pnay = NULL;
    if (!nasy)
        return ERROR_INT("nasy not defined", procName, 1);
    if (deltax <= 0.0)
        return ERROR_INT("deltax not > 0", procName, 1);
    if (type != L_LINEAR_INTERP && type != L_QUADRATIC_INTERP)
        return ERROR_INT("invalid interp type", procName, 1);
    n = numaGetCount(nasy);
    if (type == L_QUADRATIC_INTERP && n == 2) {
        type = L_LINEAR_INTERP;
        L_WARNING("only 2 points; using linear interp", procName);
    }
    maxx = startx + deltax * (n - 1);
    if (x0 < startx || x1 > maxx || x1 <= x0)
        return ERROR_INT("[x0 ... x1] is not valid", procName, 1);
    if (npts < 3)
        return ERROR_INT("npts < 3", procName, 1);
    delx = (x1 - x0) / (l_float32)(npts - 1);  
    if ((nay = numaCreate(npts)) == NULL)
        return ERROR_INT("nay not made", procName, 1);
    numaSetXParameters(nay, x0, delx);
    *pnay = nay;
    if (pnax) {
        nax = numaCreate(npts);
        *pnax = nax;
    }
    for (i = 0; i < npts; i++) {
        x = x0 + i * delx;
        if (pnax)
            numaAddNumber(nax, x);
        numaInterpolateEqxVal(startx, deltax, nasy, type, x, &yval);
        numaAddNumber(nay, yval);
    }
    return 0;
}
l_int32 numaInterpolateEqxInterval ( l_float32 startx , l_float32 deltax , NUMA * nasy , l_int32 type , l_float32 x0 , l_float32 x1 , l_int32 npts , NUMA * * pnax , NUMA * * pnay ) { l_int32 i , n ; l_float32 x , yval , maxx , delx ; NUMA * nax , * nay ; PROCNAME ( " " ) ; if ( pnax ) * pnax = NULL ; if ( ! pnay ) return ERROR_INT ( " " , procName , 1 ) ; * pnay = NULL ; if ( ! nasy ) return ERROR_INT ( " " , procName , 1 ) ; if ( deltax <= 0.0 ) return ERROR_INT ( " " , procName , 1 ) ; if ( type != L_LINEAR_INTERP && type != L_QUADRATIC_INTERP ) return ERROR_INT ( " " , procName , 1 ) ; n = numaGetCount ( nasy ) ; if ( type == L_QUADRATIC_INTERP && n == 2 ) { type = L_LINEAR_INTERP ; L_WARNING ( " " , procName ) ; } maxx = startx + deltax * ( n - 1 ) ; if ( x0 < startx || x1 > maxx || x1 <= x0 ) return ERROR_INT ( " " , procName , 1 ) ; if ( npts < 3 ) return ERROR_INT ( " " , procName , 1 ) ; delx = ( x1 - x0 ) / ( l_float32 ) ( npts - 1 ) ; if ( ( nay = numaCreate ( npts ) ) == NULL ) return ERROR_INT ( " " , procName , 1 ) ; numaSetXParameters ( nay , x0 , delx ) ; * pnay = nay ; if ( pnax ) { nax = numaCreate ( npts ) ; * pnax = nax ; } for ( i = 0 ; i < npts ; i ++ ) { x = x0 + i * delx ; if ( pnax ) numaAddNumber ( nax , x ) ; numaInterpolateEqxVal ( startx , deltax , nasy , type , x , & yval ) ; numaAddNumber ( nay , yval ) ; } return 0 ; }
numaInterpolateEqxInterval()
      Input:  startx (xval corresponding to first element in nas)
              deltax (x increment between array elements in nas)
              nasy  (numa of ordinate values, assumed equally spaced)
              type (L_LINEAR_INTERP, L_QUADRATIC_INTERP)
              x0 (start value of interval)
              x1 (end value of interval)
              npts (number of points to evaluate function in interval)
              &nax (<optional return> array of x values in interval)
              &nay (<return> array of y values in interval)
      Return: 0 if OK, 1 on error
numaInterpolateEqxInterval () Input : startx ( xval corresponding to first element in nas ) deltax ( x increment between array elements in nas ) nasy ( numa of ordinate values assumed equally spaced ) type ( L_LINEAR_INTERP L_QUADRATIC_INTERP ) x0 ( start value of interval ) x1 ( end value of interval ) npts ( number of points to evaluate function in interval ) &nax ( <optional return > array of x values in interval ) &nay ( <return > array of y values in interval ) Return : 0 if OK 1 on error
/* delx is for output nay */