Next Previous Contents

2. Using the GSL Modules

To use one of the GSL modules in a S-lang script, it is first necessary to import the gslcore module before importing the desired GSL module. For example, to load the GSL special function module, use

    import ("gslcore");
    import ("gslsf");
Failure to first load the gslcore module may result in an error message such as
    Error linking to gslsf-module.so
Another alternative is to load the gslsf.sl via
    () = evalfile ("gsl.sl");
or, if the application supports the require function, via
    require ("gslsf");

Similarly, the gsl.sl file exists as a convenient way to load all GSL modules (gslcore, gslsf, gslrand, gslconst, and gslinterp), i.e.,

    require ("gsl");

Finally, it may be desirable to import the GSL module into a separate namespace. For example, to load the GSL special function module gslsf into a namespace called gsl, use

    import ("gslcore", "gsl");
    import ("gslsf", "gsl");
Then to access, e.g., the hypot function, use the gsl->hypot. See the S-Lang documentation for more information about namespaces.

Once the desired module has been loaded, intrinsics functions and variables defined by the module may be used in the usual way, e.g.,

    require ("gslsf");
        .
        .
    % Use the GSL hypot function to filter a list of (x,y) pairs
    % to those values that fall in a circle of radius R centered 
    % on (0,0)
    define filter_region_in_circle (x, y, R)
    {
       variable i = where (hypot (x,y) < R);
       return (x[i], y[i]);
    }


Next Previous Contents