MGL script language is rather simple. Each string is a command. First word of string is the name of command. Other words are command arguments. Words are separated from each other by space or tabulation symbol. The upper or lower case of words is important, i.e. variables a and A are different variables. Symbol ‘#’ starts the comment (all characters after # will be ignored). The exception is situation when ‘#’ is a part of some string. Also options can be specified after symbol ‘;’ (see Command options). Symbol ‘:’ starts new command (like new line character) if it is not placed inside a string or inside brackets.
If string contain references to external parameters (substrings ‘$0’, ‘$1’ ... ‘$9’) or definitions (substrings ‘$a’, ‘$b’ ... ‘$z’) then before execution the values of parameter/definition will be substituted instead of reference. It allows one to use the same MGL script for different parameters (filenames, paths, condition and so on).
Argument can be a string, a variable (data arrays) or a number (scalars).
'b'
);
'abf'
).
new x 100 'x':copy !b !exp(1i*x)
will create real valued data x and complex data b, which is equal to exp(I*x), where I^2=-1. A temporary array can be used as variable too:
a(1)
or a(1,:)
or a(1,:,:)
is second row, a(:,2)
or a(:,2,:)
is third column, a(:,:,0)
is first slice and so on. Also you can extract a part of array from m-th to n-th element by code a(m:n,:,:)
or just a(m:n)
.
a('n*w^2/exp(t)')
if names for data columns was specified (by idset command or in the file at string started with ##
).
tmp[i,j] = sqrt(dat[i,5,j]+1)
. At this symbol ‘`’ will return transposed data array: both ‘`sqrt(dat(:,5)+1)’ and ‘sqrt(`dat(:,5)+1)’ will produce temporary variable with data values equal to tmp[i,j] = sqrt(dat[j,5,i]+1)
.
Temporary variables can not be used as 1st argument for commands which create (return) the data (like ‘new’, ‘read’, ‘hist’ and so on).
nan=#QNAN, inf=INFINITY, rnd=random value, pi=3.1415926..., on=1, off=0, all=-1, :=-1
, variables with suffixes (see Data information), names defined by define command, time values (in format "hh-mm-ss_DD.MM.YYYY", "hh-mm-ss" or "DD.MM.YYYY") are treated as number. Also results of formulas with sizes 1x1x1 are treated as number (for example, ‘pi/dat.nx’).
Before the first using all variables must be defined with the help of commands, like, new, var, list, copy, read, hist, sum and so on (see sections Data constructor, Data filling and Make another data).
Command may have several set of possible arguments (for example, plot ydat
and plot xdat ydat
). All command arguments for a selected set must be specified. However, some arguments can have default values. These argument are printed in [], like text ydat ['stl'='']
or text x y 'txt' ['fnt'='' size=-1]
. At this, the record [arg1 arg2 arg3 ...]
means [arg1 [arg2 [arg3 ...]]]
, i.e. you can omit only tailing arguments if you agree with its default values. For example, text x y 'txt' '' 1
or text x y 'txt' ''
is correct, but text x y 'txt' 1
is incorrect (argument 'fnt'
is missed).
You can provide several variants of arguments for a command by using ‘?’ symbol for separating them. The actual argument being used is set by variant. At this, the last argument is used if the value of variant is large than the number of provided variants. By default the first argument is used (i.e. as for variant 0
). For example, the first plot will be drawn by blue (default is the first argument ‘b’), but the plot after variant 1
will be drawn by red dash (the second is ‘r|’):
fplot 'x' 'b'?'r' variant 1 fplot 'x^3' 'b'?'r|'