Last modified: 12 December 2018

How do I convert my S-Lang scripts?


The CIAO 4.3 release of ChIPS removed support for S-Lang in ChIPS. The Conversion Guides section of the ChIPS web site includes general advice on updating ChIPS scripts between versions of CIAO. If you need help converting any existing scripts to Python, please contact the CXC Helpdesk. Relevant data files may be placed on the FTP site (FTP Instructions).

For simple scripts it can be as easy as the following steps:

  1. remove the trailing ; character;

  2. for routines called no arguments, S-Lang allows you to ignore the trailing () but these are required for Python (examples include info and clear);

  3. change lists from "{...}" to "[...]";

  4. boolean arguments in S-Lang were represented using 0 or 1 whereas you can now use the Python boolean values False or True;

  5. change strings like "\delta = 23"R to r"\delta = 23" (the trailing R character becomes a leading r to avoid having to write \\ instead of \);

  6. remove the variable term (i.e. no need to declare variable names);

  7. the print routine can be used instead of message and vmessage (string formatting or interpolation can be done using the format method or the deprecated % operator);

  8. use

    from pychips import *
    from pychips.hlui import *
    from pycrates import *
    

    rather than

    require("chips");
    require("chips_hlui");
    require("crates");
    

    to load ChIPS and Crates.

An example of a simple conversion is given below:

S-Lang Python
#!/usr/bin/env slsh #!/usr/bin/env python
require("chips"); from pychips import *
require("chips_hlui"); from pychips.hlui import *
set_preference("window.display", "false"); set_preference("window.display", "false")
add_curve("src.fits[cols x,y]"); add_curve("src.fits[cols x,y]")
set_curve({"symbol.style", "none", "line.color", "red"}); set_curve(["symbol.style", "none", "line.color", "red"])
variable cr = read_file("src2.fits"); cr = read_file("src2.fits")
variable x = copy_colvals(cr, "x"); x = copy_colvals(cr, "x")
variable y = copy_colvals(cr, "y"); y = copy_colvals(cr, "y")
add_curve(x, y, {"line.color", "orange", "symbol.style", "none"}); add_curve(x, y, ["line.color", "orange", "symbol.style", "none"])
set_plot_title("\alpha=2.3 \pm 0.2"R); set_plot_title(r"\alpha=2.3 \pm 0.2")
print_window("plot.pdf", {"fittopage", 1, "clobber", 1}); print_window("plot.pdf", ["fittopage", True, "clobber", True])