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 ARG1 ... ARG9 are stored in ordinary string variables they may be dereferenced by macro expansion (analogous to the older deprecated syntax). However in many cases it is more natural to use them as you would any other variable.

In parallel to the string parameters ARG1 ... ARG9, the passed parameters are stored in an array ARGV[9]. See argv.

Argv[ ]

When a gnuplot script is entered via the call command any parameters passed by the caller are available via two mechanisms. Each parameter is stored as a string in variables ARG1, ARG2, ... ARG9. Each parameter is also stored as one element of the array ARGV[9]. Numerical values are stored as complex variables. All other values are stored as strings. Thus after a call
call 'routine_1.gp'  1 pi "title"

The three arguments are available inside routine_1.gp as follows

ARG1 = "1"         ARGV[1] = 1.0
ARG2 = "3.14159"   ARGV[2] = 3.14159265358979...
ARG3 = "title"     ARGV[3] = "title"

In this example ARGV[1] and ARGV[2] have the full precision of a floating point variable. ARG2 lost precision in being stored as a string using format "%g".

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 because ARG1 is a string it 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 deprecated call mechanism used by old versions of gnuplot.
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.

Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
Distributed under the gnuplot license (rights to distribute modified versions are withheld).