Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pmi432 / LR02 / Books / gnuplot 4.6 manual.pdf
Скачиваний:
55
Добавлен:
18.03.2015
Размер:
2.22 Mб
Скачать

40

gnuplot 4.6

plot "foo" using 1:3 with lines lt 4 lw 2, \ "bar" using 1:5 with points lt 3 pt 5 ps 2

The function exists() may be useful in connection with macro evaluation. The following example checks that C can safely be expanded as the name of a user-de ned variable:

C = "pi"

if (exists(C)) print C," = ", @C

Macro expansion does not occur inside either single or double quotes. However macro expansion does occur inside backquotes.

Macro expansion is handled as the very rst thing the interpreter does when looking at a new line of commands and is only done once. Therefore, code like the following will execute correctly:

A = "c=1" @A

but this line will not, since the macro is de ned on the same line and will not be expanded in time

A = "c=1"; @A # will not expand to c=1

For execution of complete commands the evaluate command may also be handy.

String variables, macros, and command line substitution

The interaction of string variables, backquotes and macro substitution is somewhat complicated. Backquotes do not block macro substitution, so

filename = "mydata.inp"

lines = ` wc --lines @filename | sed "s/ .*//" `

results in the number of lines in mydata.inp being stored in the integer variable lines. And double quotes do not block backquote substitution, so

mycomputer = "`uname -n`"

results in the string returned by the system command uname -n being stored in the string variable mycomputer.

However, macro substitution is not performed inside double quotes, so you cannot de ne a system command as a macro and then use both macro and backquote substitution at the same time.

machine_id = "uname -n"

mycomputer = "`@machine_id`" # doesn't work!!

This fails because the double quotes prevent @machine id from being interpreted as a macro. To store a system command as a macro and execute it later you must instead include the backquotes as part of the macro itself. This is accomplished by de ning the macro as shown below. Notice that the sprintf format nests all three types of quotes.

machine_id = sprintf('"`uname -n`"') mycomputer = @machine_id

Syntax

Options and any accompanying parameters are separated by spaces whereas lists and coordinates are separated by commas. Ranges are separated by colons and enclosed in brackets [], text and le names are enclosed in quotes, and a few miscellaneous things are enclosed in parentheses.

Commas are used to separate coordinates on the set commands arrow, key, and label; the list of variables being tted (the list after the via keyword on the t command); lists of discrete contours or the loop

Соседние файлы в папке Books