((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/bvsp-spline" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "eggs") (toc)) (section 2 "bvsp-spline" (section 3 "Description" (p "The Chicken " (tt "bvsp-spline") " library provides bindings to the routines in the " (tt "BVSPIS") " Fortran library. " (link "http://www.netlib.org/toms/" "BVSPIS") " (Boundary-Valued Shape-Preserving Interpolating Splines) is a package for computing and evaluating shape-preserving interpolating splines, and is described in") (pre "P. Costantini. Algorithm 770: BVSPIS -- a package for computing boundary-valued shape-preserving interpolating splines. \nACM Trans. Math. Softw. 23, No.2, 252-254 (1997)")) (section 3 "Installation notes" (p "The Chicken " (tt "bvsp-spline") " library must be compiled along with the " (tt "BVSPIS") " Fortran source code, however the ACM licensing terms prevent the distribution of " (tt "BVSPIS") " via the Chicken package system.") (p "Therefore, the user must download and unpack " (tt "BVSPIS") ", and set the " (tt "BVSPIS_PATH") " environment variable to indicate the location where the sources can be found. " (tt "chicken-install") " can then be invoked as usual.") (p "The following commands perform the necessary operations when invoked from bash in a typical Linux distribution:") (pre " wget http://www.netlib.org/toms/770\n mkdir bvspis && awk 'NR>4' 770 > bvspis/bvspis.sh && chmod u+x bvspis/bvspis.sh\n pushd bvspis && ./bvspis.sh && popd\n BVSPIS_PATH=$PWD/bvspis chicken-install bvsp-spline")) (section 3 "Library procedures" (def (sig (procedure "(compute n k x y #!key (shape-constraint 'none) (boundary-condition 'none) (derivative-computation 'order2) (d0 #f) (dnp #f) (d20 #f) (d2np #f) (eps 1e-4) (constr #f) (beta #f) (betainv #f) (rho #f) (rhoinv #f) (kmax #f) (maxstp #f) (d #f) (d2 #f) ) " (id compute))) (p "Computes the coefficients of a shape-preserving spline, of continuity class C(k), k=1,2 , which interpolates a set of data points and, if required, satisfies additional boundary conditions.") (p "The result of the routine is a list of the form " (tt "(D D2 CONSTR ERRC DIAGN)") ".  " (tt "D D2 ERRC") " provide the input parameters for " (tt "evaluate") ", which evaluates the spline and its derivatives along a set of tabulation points. " (tt "CONSTR") " is an SRFI-4 " (tt "s32vector") " that contains computed constraint information.") (p "The required arguments are:") (dl (dt "N") (dd "the degree of the spline (must be integer >= 3)") (dt "K") (dd "the class of continuity of the spline (first or second derivative). K=1 or K=2 and N >= 3*K") (dt "X") (dd "SRFI-4 " (tt "f64vector") " value containing the x coordinates of the data points (must be the same length as Y)") (dt "Y") (dd "SRFI-4 " (tt "f64vector") " value containing the y coordinates of the data points (must be the same length as X)")) (p "The optional arguments are:") (dl (dt "shape-constraint") (dd "one of " (tt "'none") ", " (tt "'monotonicity") ", " (tt "'convexity") ", " (tt "'monotonicity+convexity") ", " (tt "'local") ". Default is " (tt "'none")) (dt "boundary-condition") (dd "one of  " (tt "'none") ", " (tt "'non-separable") ", " (tt "'separable") ". Default is " (tt "'none")) (dt "derivative-computation") (dd "one of " (tt "'order1") ", " (tt "'order2") ", " (tt "'order3") ", " (tt "'classic") ". Default is " (tt "'order2")) (dt "d0") (dd "left separable boundary condition for the first derivative (only used when " (tt "boundary-condition") " is " (tt "'separable") ")") (dt "dnp") (dd "right separable boundary condition for the first derivative (only used when " (tt "boundary-condition") " is " (tt "'separable") ")") (dt "d20") (dd "left separable boundary condition for the second derivative (only used when " (tt "boundary-condition") " is " (tt "'separable") " and K=2)") (dt "d2np") (dd "right separable boundary condition for the second derivative (only used when " (tt "boundary-condition") " is " (tt "'separable") " and K=2)") (dt "eps") (dd "relative tolerance of the method. Default is 1e-4") (dt "constr") (dd "if " (tt "shape-constraint") " is " (tt "'local") ", this argument containts a " (tt "s32vector") " value with the desired constraints on the shape for each subinterval. Each element can be one of 0,1,2,3 (none, monotonicity, convexity, monotonicity and convexity constraint)") (dt "beta") (dd "user-supplied procedure of the form " (tt "(LAMBDA X)") ", which represents non-separable boundary conditions for the first derivatives (only used  when " (tt "boundary-condition") " is " (tt "'non-separable") ")") (dt "betainv") (dd "user-supplied procedure of the form " (tt "(LAMBDA X)") ", which is the inverse of " (tt "BETA") " (only used  when " (tt "boundary-condition") " is " (tt "'non-separable") ")") (dt "rho") (dd "user-supplied procedure of the form " (tt "(LAMBDA X)") ", which represents non-separable boundary conditions for the second derivatives (only used  when " (tt "boundary-condition") " is " (tt "'non-separable") " and K=2)") (dt "rhoinv") (dd "user-supplied procedure of the form " (tt "(LAMBDA X)") ", which is the inverse of " (tt "RHO") " (only used  when " (tt "boundary-condition") " is " (tt "'non-separable") " and K=2)") (dt "kmax") (dd "the number of iterations allowed for selecting the minimal set " (tt "ASTAR") " (described in the paper)") (dt "maxstp") (dd "the number of iterations allowed for finding the set " (tt "DSTAR") " (described in the paper)") (dt "d") (dd "SRFI-4 " (tt "f64vector") " value containing the first derivatives at the points in X (only used when " (tt "derivative-computation") " is " (tt "'classic") ")") (dt "d2") (dd "SRFI-4 " (tt "f64vector") " value containing the second derivatives at the points in X (only used when " (tt "derivative-computation") " is " (tt "'classic") " and K=2)"))) (def (sig (procedure "(evaluate n k x y d d2 xtab errc #!key (search-method 'binary) (derivatives 2))" (id evaluate))) (p "Evaluates the given spline at points given by argument " (tt "XTAB") ", which must be an SRFI-4 " (tt "f64vector") " value.  Arguments " (tt "N K X Y") " have the same meaning as for the " (tt "compute") " routine. Arguments " (tt "D D2 ERRC") " are produced by " (tt "compute") "."))) (section 3 "Example" (pre "(use srfi-1 srfi-4 bvsp-spline)\n\n;;  Input data \n\n(let ((x (f64vector .000000000E+00\n\t\t    .628318500E+00\n\t\t    .125663700E+01\n\t\t    .188495600E+01\n\t\t    .251327400E+01\n\t\t    .314159300E+01\n\t\t    .376991100E+01\n\t\t    .439823000E+01\n\t\t    .502654800E+01\n\t\t    .565486700E+01\n\t\t    .628318500E+01))\n      (y (f64vector .200000000E+00\n\t\t    .387785300E+00\n\t\t    .115105700E+01\n\t\t    .751056500E+00\n\t\t    .787785200E+00\n\t\t    -.200000100E+00\n\t\t    -.387785300E+00\n\t\t    -.115105700E+01\n\t\t    -.751056500E+00\n\t\t    -.787784900E+00\n\t\t    .200000200E+00)))\n\n  ;;  Set the degree and the class of continuity of the spline.\n  (let ((n 3) (k 1))\n    \n    (let-values (((d d2 constr errc diagn)\n\t\t  (compute n k x y)))\n\n      (assert (zero? errc))\n\n      (let* ((xpn 100)\n\t     (dxp (/ (- (f64vector-ref x (- (f64vector-length x) 1)) (f64vector-ref x 0)) xpn))\n\t     (xp  (list->f64vector (list-tabulate 100 (lambda (i) (* i dxp))))))\n\t\n\t(let-values (((y0tab y1tab y2tab erre) (evaluate n k x y d d2 xp errc)))\n\t  \n\t  (print \"erre = \" erre)\n  \n  (for-each (lambda (i v)\n\t      (printf \"y0tab(~A) = ~A~%\" (f64vector-ref xp i) (f64vector-ref y0tab i))\n\t      )\n\t\t    '(32 65 98)\n\t\t    '(0.746843749779158 -0.806157453777544 -0.0795180362289622))\n\t  )))\n    ))")) (section 3 "Version History" (ul (li "1.0 Initial release"))) (section 3 "License" (pre " Copyright 2011 Ivan Raikov.\n All rights reserved.") (pre "This program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or (at\nyour option) any later version.\n\nThis program is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\nGeneral Public License for more details.\n\nA full copy of the GPL license can be found at\n<http://www.gnu.org/licenses/>."))))