SLATEC in SDSSMATH tutorial

More information on the detailed use of these calls is on the SDSS SLATEC page. The bindings have been made with variable names as similar as possible to allow the original SLATEC documentation to be useful. Here we illustrate the basic use so you know what is available. The tests in sdssmath/tst also serve to illustrate the basic functionality of slatec bindings in sdssmath.

The philosophy of FUNC

All fits are described in the FUNC structure, which consists of a name, an array of pointers to VECTORs, fit quality information (chi2, covariance matrix) and a pointer to a function. These are created with funcNew and deleted with funcDel. funcNew takes a number of VECTORs as input and does a brief sanity check. Any FUNC can be evaluated at an x value with funcEval. Using a METH (currently, only chi2 is defined) a set of x,y points can be fit to a FUNC with dnls1 (including covariance matrix calculation) or dnsl1e (the "easy" version).

BSPLINE fitting

The tcl binding to interpolate a set of x,y points with a cubic spline is dbint4. Its use is illustrated in sdssmath/test/tst_dbs.tcl:
sdssmath> source tst_dbs.tcl
0
sdssmath> pgInit
Open /xwindow
sdssmath> tst_dbs 1
Do the plot
xmin=0.158079 xmax=6.1250999999999998
0
The plot shows the points on the cos curve, and then the residuals of the BSPLINE interpolation.

Polynomial fitting

Use dpolft to fit a polynomial and dp1valu to evaluate the value (or a derivative) at any point. The use is illustrated in sdssmath/test/tst_dpo.tcl:
sdssmath> source tst_dpo.tcl
0
sdssmath> pgInit /xwindow
Open /xwindow
sdssmath> tst_dpo 1
Do the plot
begin l=6
begin l=8
begin l=10
0
sdssmath>      

Least Squares Fitting

There are two calls that perform minimization: dnls1 and dnls1e. dnls1e is the "easy" version, and dnls1 requires a few more inputs but also calculates the covariance matrix for you. Its use is illustrated in sdssmath/test/tst_dnls1lin.tcl for a linear model (to test the error matrix calculation in a case where we know the answer) and in tst_dnls1.tcl for a fit to a gaussian.
sdssmath> source tst_dnls1.tcl
0
sdssmath> tst_dnls1 /xwindow
Open /xwindow
0
A similar test for the linear fit is in sdssmath/test/tst_dnls1lin.tcl

Plotting Functions

The tcl binding funcPlot uses the values in the pg variable (which is created with pgInit) to define where and how to plot the function. The following elements of the pg variable are used:

Handle those errors!

A call to the SLATEC subroutine xsetf defines how you want SLATEC routines to behave when they get in trouble. This is called as smaXsetf(0) in programs linked with the sdssmath TCL verbs defined, to tell SLATEC to keep on running if it gets into trouble. Calling it with a value of 1 or 2 makes it more sensitive to errors. See the SLATEC pages for more details.