Next: Scripting sm Up: sm Previous: sm

### Interactive sm

To use sm interactively, simply type sm. You will be asked to enter a command. Try the following (hit RETURN after each line):

```    dev x11
box
relocate 0 0
draw 1 1
```

If all went well an X window popped up after the device (shorthand dev) command, axes with values ranging from 0 to 1 appeared, and a diagonal line from the lower left corner to the upper right was drawn.

Now in another window create a file called sq.dat that looks like this:

```    1 1
2 4
3 9
4 16
5 25
6 36
7 51
8 64
9 81
10 100
```

sm interprets whitespace as column delimiters, much like awk. In sm type:

```    data sq.dat
erase
limits n s
box
points n s
```

You should see half a parabola worth of ``x''s. The read command loaded two vectors, in this example we called them n and s, with the corresponding columns of the data file. The limits command set the plot limits automatically based on the values in n and s. The box command drew the axes (use xlabel and ylabel to make axis labels) and points drew the points. If you don't like the point size, try expand 2 to make everything double size (you'll need to redraw the points). You can also experiment with the ptype command (try ptype 3 0 for example). Hint: If your terminal settings are set correctly, you can use the up and down arrow keys to cycle through the command history. Now try the following:

```    set n2 = n*n
connect n n2
```

The set command allows you to make a new vector or modify an existing one. The connect command connects points. You should notice the point for N=7 lies off the curve (yes, that was deliberate). You may also notice the curve is a bit jagged (particularly if you replot the curve without doing points first). Let's use 100 points instead:

```    erase
box
set i = 1,100
set n2 = i*i
connect i n2
points n s
```

(If you're using expand 2 you'll notice the axis labels and ticks got bigger). Note how we were able to create the vector i. Now try this:

```    ctype red
histogram n s
```

Assuming you're in front of a colour screen you should now have steps drawn in red going up the curve. If you prefer your histograms to have bars that go all the way down, use barhist 100 n s instead (the optional numeric value specifies the percentage width of the bars). To go back to drawing in the default colour, type ctype default (this is preferable to ctype white because the latter won't work very well on white paper, whereas the former automatically knows to switch to a black foreground).

For more help on a particular function, simply type help function. You may also find the apropos command useful. And there's always the manual. Some of the most popular commands, in addition to what we've seen so far, are: define, do, draw, errorbar, if, ltype, lweight, macro, putlabel, relocate, sort, ticksize, window, and while. Also try help arithmetic to see what math operators and functions are supported, and list device to see what devices are available (e.g. to output everything to an encapsulated postscript file, use dev postencap myfile.eps instead of dev x11).

Next: Scripting sm Up: sm Previous: sm
Massimo Ricotti 2009-01-26