Gnuplot 5.2.7

Call

The call command is identical to the load command with one exception: the name of the file being loaded may be followed by up to nine parameters.

call "inputfile" <param-1> <param-2> <param-3> ... <param-9>

Previous versions of gnuplot performed macro-like substitution of the special tokens $0, $1, ... $9 with the literal contents of these parameters. This mechanism is now deprecated (see call old-style).

Gnuplot now provides a set of string variables ARG0, ARG1, ..., ARG9 and an integer variable ARGC. When a call command is executed ARG0 is set to the name of the input file, ARGC is set to the number of parameters present, and ARG1 to ARG9 are loaded from the parameters that follow it on the command line. Any existing contents of the ARG variables are saved and restored across a call command.

Because the parameters are stored in ordinary string variables, they may be dereferenced by macro expansion (analogous to the old-style deprecated syntax). However in many cases it is more natural to use them as you would any other variable.

Example

Call site
    MYFILE = "script1.gp"
    FUNC = "sin(x)"
    call MYFILE FUNC 1.23 "This is a plot title"
Upon entry to the called script
    ARG0 holds "script1.gp"
    ARG1 holds the string "sin(x)"
    ARG2 holds the string "1.23"
    ARG3 holds the string "This is a plot title"
    ARGC is 3
The script itself can now execute
    plot @ARG1 with lines title ARG3
    print ARG2 * 4.56, @ARG2 * 4.56
    print "This plot produced by script ", ARG0

Notice that ARG1 must be dereferenced as a macro, but ARG2 may be dereferenced either as a macro (yielding a numerical constant) or a variable (yielding that same numerical value after auto-promotion of the string "1.23" to a real).

The same result could be obtained directly from a shell script by invoking gnuplot with the -c command line option:

gnuplot -persist -c "script1.gp" "sin(x)" 1.23 "This is a plot title"

Old-style

This describes the call mechanism used by older versions of gnuplot, now deprecated.

call "<input-file>" <param-0> <param-1> ... <param-9>

The name of the input file must be enclosed in quotes. As each line is read from the input file, it is scanned for the following special character sequences: $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $#. If found, the sequence $+digit is replaced by the corresponding parameter from the call command line. Quote characters are not copied and string variable substitution is not performed. The character sequence $# is replaced by the number of passed parameters. $ followed by any other character is treated as an escape sequence; use $$ to get a single $.

Example:

If the file 'calltest.gp' contains the line:

print "argc=$# p0=$0 p1=$1 p2=$2 p3=$3 p4=$4 p5=$5 p6=$6 p7=x$7x"

entering the command:

call 'calltest.gp' "abcd" 1.2 + "'quoted'" -- "$2"

will display:

argc=7 p0=abcd p1=1.2 p2=+ p3='quoted' p4=- p5=- p6=$2 p7=xx

NOTES: This use of the $ character conflicts both with gnuplot's own syntax for datafile columns and with the use of $ to indicate environmental variables in a unix-like shell. The special sequence $# was mis-interpreted as a comment delimiter in gnuplot versions 4.5 through 4.6.3. Quote characters are ignored during substitution, so string constants are easily corrupted.