4.2 Programming with plotdata macros

When you quit, plotdata also forgot all of its settings, not just the data values, so you had to re-enter the label strings and all other commands. In general, computers are very good at repetitive tasks, and one should never have to type the same thing twice! In plotdata you can create ``programs'' of plotdata commands called macros.

For example, quit or move to another window, and use your favourite editor to create a plain text file named graph2d.PCM, with the following lines in it:

read file.dat x,y,dy
vary a
fit y=a*x
upd f
xlab "Time, s"
ylab "Distance, m"
clear
pch -10
gra x,y,dy
pch 0
gra/noax x,f

These are exactly the same commands that we have used before, except we have abbreviated a few of them (non-ambiguous abbreviations are allowed in plotdata). When you re-start plotdata now, all you need to do to repeat the plot of Figure 1 is:

PLOTDATA: execute graph2d

Since we have used the default file extension in naming the macro (.PCM, note the capitalization), we do not need to type it in, plotdata supplies it automatically. The above line ``executes'' a macro contained in the file graph2d.PCM with all the right commands.

To analyze another set of data from a similar experiment you would have to edit the macro file graph2d.PCM, replace the file name file.dat with a new one, and then repeat the above.

Actually, there is a way to build a ``universal'' macro! Change the first line in your macro to

read ?1 x,y,dy

By specifying ?1 in place of the file name you are telling plotdata to get the file name from you at the time of execution of the macro, like this:

PLOTDATA: execute graph2d file.dat

meaning ``read the data from the file whose name is contained in the parameter No.1 (?1) on the command line into vectors x, y, and dy''. And the name we supply on the above line is the same file.dat as before. For another set of data you could generate the graph with a single plotdata command, by simply specifying a different filename instead of file.dat!

Test your understanding of the above macro by modifying it to allow passing the plotting character code as the second parameter. Within the macro you would then refer to it as ?2 and from plotdata you would call it up like this:

PLOTDATA: exe graph2d file.dat 10

to use triangles again (note the abbreviation of the word execute); or

PLOTDATA: @graph2d file.dat 4

to use crosses (for example) at the data points. The symbol @ is another shorthand for execute.

Up: 4. A simple example Next: 4.3 Getting help Previous: 4.1 Reading data into plotdata