next up previous
Next: Other Graphing Packages Up: sm Previous: Interactive sm


Scripting sm

The commands in the example above could all be placed in a file, say sq.sm, and read in like this: sm inp_new sq.sm. This is useful if you plan to look at data of this nature over and over. It's particularly useful if you first want to look at the output on the screen and then later print to a file. Note however there were a few erases above, and these cause the plots to flash by. Here's a way to handle such cases:

    define ps 0 # use 0 for screen output, 1 for file output
    macro pause {
        define dum ('c') # default is to continue 
        while {1} { # keep looping until a valid response is given
            define dum ? {Type c to continue or q to quit}
            if ('$dum' == 'q') {quit}
            if ('$dum' == 'c') {return}
        }
    }
    macro next {
        if ($ps) {
            hardcopy
        } else { # NOTE: the else MUST be on the same line as } and {
            pause
            erase
        }
    }
    #
    # execution begins here...
    if ($ps) {
        dev postencap myfile.eps
    } else {
        dev x11
    }

Here we've used the define command to create scalars (as opposed to vectors). Note that the value of a scalar can be obtained by prepending a dollar sign: $ps. If the lines above are added at the start of the script, you could replace all erase calls with our user-defined macro next. The user would then be prompted to press RETURN before the next plot is drawn. Notice that if ps is defined then a hardcopy command is issued instead, which sends a print request to a file (or printer). Alternatively you could use the window command to put more than one plot on the screen at once, but there's a limit to how many plots you can cram in this way.

Commonly used macros can be stored in a file by themselves and read in with the command macro read macrofile before doing anything else. This is how method 2 of using sm works.

sm can be about as frustrating as (t)csh at times as far as remembering the correct syntax, perhaps more so. Trial and error is your best bet. As a general rule of thumb, an expression used as an argument to a define command should be in ( ) and any string value should be quoted '' just to be safe.


next up previous
Next: Other Graphing Packages Up: sm Previous: Interactive sm
Massimo Ricotti 2009-01-26