Call ChIPS commands from S-Lang
Integer_Type chips_eval(String_Type)
The chips_eval() function allows S-Lang code to execute ChIPS commands
which do not have a corresponding S-Lang version.
To do this, you create a string which contains the command to execute
and pass it to chips_eval(), which returns a 0 on success and a -1 on failure.
() = chips_eval("xlabel 'TIME (s)'");
() = chips_eval("xlabel size 1.5");
These two lines -
if included in a S-Lang script which has already
loaded the ChIPS module with a
call - will change the x-axis label to "TIME (s)"
and the size of the label to 1.5.
We use "() = " to ignore the return value of the
call (i.e. whether it succeeded or not).
The "chips_eval()" function can be used to write your
own S-Lang versions of ChIPS commands.
The example file listed below ("axis.sl") defines
a S-Lang function called "xaxis()" which takes
one argument - the label for the X axis. It uses
"chips_eval()" to call the ChIPS XLABEL command twice;
first to set the label axis and the second the size
of the label. The use of "string(label)" means that
the function can be called with a numeric argument
(since the numeric value will be converted to a string
by this function) as well as a string.
Before calling XLABEL we turn off the redraw mode - using
chips_auto_redraw() - to avoid the plot flashing. The
original value for this mode is reset after the chips_eval() calls
are made.
unix% cat axis.sl
define xaxis(label) {
variable oldval = chips_auto_redraw(0);
() = chips_eval( "xlabel '" + string(label) + "'" );
() = chips_eval( "xlabel size 1.5" );
() = chips_auto_redraw(oldval);
}
This can then be used by:
chips> () = evalfile("axis.sl")
chips> xaxis("TIME (s)")
The evalfile call can also be included in your
.chipsrc resource file to make sure the
function is available each time you use ChIPS.
|