14.10.2014 Views

gnuplot documentation

gnuplot documentation

gnuplot documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

20 SUBSTITUTION AND COMMAND LINE <strong>gnuplot</strong> MACROS 4.3 37<br />

20 Substitution and Command line macros<br />

When a command line to <strong>gnuplot</strong> is first read, i.e. before it is interpreted or executed, two forms of<br />

lexical substitution are performed. These are triggered by the presence of text in backquotes (ascii<br />

character 96) or preceded by @ (ascii character 64).<br />

20.1 Substitution of system commands in backquotes<br />

Command-line substitution is specified by a system command enclosed in backquotes. This command<br />

is spawned and the output it produces replaces the backquoted text on the command line. Some<br />

implementations also support pipes; see plot datafile special-filenames (p. 72).<br />

Command-line substitution can be used anywhere on the <strong>gnuplot</strong> command line, except inside strings<br />

delimited by single quotes.<br />

Example:<br />

This will run the program leastsq and replace leastsq (including backquotes) on the command line<br />

with its output:<br />

or, in VMS<br />

f(x) = ‘leastsq‘<br />

f(x) = ‘run leastsq‘<br />

These will generate labels with the current time and userid:<br />

set label "generated on ‘date +%Y-%m-%d‘ by ‘whoami‘" at 1,1<br />

set timestamp "generated on %Y-%m-%d by ‘whoami‘"<br />

20.2 Substitution of string variables as macros<br />

Substitution of command line macros is disabled by default, but may be enabled using the set macros<br />

command. If macro substitution is enabled, the character @ is used to trigger substitution of the current<br />

value of a string variable into the command line. The text in the string variable may contain any<br />

number of lexical elements. This allows string variables to be used as command line macros. Only string<br />

constants may be expanded using this mechanism, not string-valued expressions. For example:<br />

set macros<br />

style1 = "lines lt 4 lw 2"<br />

style2 = "points lt 3 pt 5 ps 2"<br />

range1 = "using 1:3"<br />

range2 = "using 1:5"<br />

plot "foo" @range1 with @style1, "bar" @range2 with @style2<br />

The line containing @ symbols is expanded on input, so that by the time it is executed the effect is<br />

identical to having typed in full<br />

plot "foo" using 1:3 with lines lt 4 lw 2, \<br />

"bar" using 1:5 with points lt 3 pt 5 ps 2<br />

The function exists() may be useful in connection with macro evaluation. The following example checks<br />

that C can safely be expanded as the name of a user-defined variable:<br />

C = "pi"<br />

if (exists(C)) print C," = ", @C<br />

Macro expansion does not occur inside either single or double quotes. However macro expansion does<br />

occur inside backquotes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!