Go to the previous, next section.

What is a plot macro, and how do I make one?

A plot macro is a set of commands that you can execute together by invoking the name of the macro; in effect, it is a plot subroutine. For example, suppose you had a set of plots that you wanted to generate, using the same type of axis box and labels. Rather than laboriously typing the box and label and limits commands for each set of data, you could define a macro as follows:

        drawbox         # this is a comment
                        limits 0 20 0 100
                        box
                        xlabel xdata
                        ylabel ydata
where the macro name in this example is drawbox. Then, when you access your data, you could do as follows:
        data file1.dat
        read { x 1 y 2 2
        drawbox
        connect x y
        data file2.dat
        read x 3
        read y 7
        drawbox
        connect x y
(The read { x 1 y 2 2 is the same as read x 1 read y 2, but faster). This is a simple-minded example, and you can immediately see ways to improve the macro I have created to save even more typing. Macros may consist of any SM commands, and may have arguments. You specify the number of arguments in the macro definition, and refer to them by number, preceded by $. In the example I gave above, suppose we wanted to make the axis labels into variables. Then the macro definition would look like this:
        drawbox 2       # this is also a comment
                        limits 0 20 0 100
                        box
                        xlabel $1
                        ylabel $2
Then to invoke the macro, I type
        drawbox xdata ydata

You can make a macro in 4 ways:

a.
You can create it with your favorite editor outside of SM. The rule to remember if you do this is that the name of the macro must be the first thing on a line of the file, and should be followed by SM commands. All the commands must start in a column in the file other than the first column. To read this macro into SM, use the macro read command
        macro read macro.file
will read all the macros in the file macro.file.

b.
You can define the macro within SM by extracting a set of commands from the history buffer
        macro mname 1 20
will extract lines 1 through 20 from the history buffer, and create the macro mname which consists of those 20 lines.

c.
You can define the macro within SM with the macro command
        macro mname {
will start the definition of the macro named mname. You then enter SM commands, and terminate the macro definition with a closing }.

d.
You can define the macro within SM with the macro edit command
        macro edit mname
will invoke the macro editor, and you can then enter SM commands to define the macro. The editor is described in detail in the SM manual; the main commands to remember are as follows: In the following descriptions ^X means hold down the CTRL key and then press the X key

Go to the previous, next section.