S-Lang GSL Module Reference: Using the GSL Modules

Next Previous Contents

## 2. Using the GSL Modules

To use one of the GSL modules in a S-lang script, the module must first be loaded using the `require` function. For example, to load the GSL special function module, use

> `

>        require ("gslsf");

> `

The `gsl.sl` file exists as a convenient way to load all GSL modules (`gslsf`, `gslrand`, etc.), e.g.,

> `

>         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

> `

>        require ("gsl", "G")

> `

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