Expressions


You can write compound expressions in GDL statements. Expressions can be of numerical and string type.
They are constants, variables, parameters or function calls and any combination of these in operators.
Round bracket pairs (( )) (precedence 1) are used to override the default precedence of the operators.

Simple type variables can be given numerical and string values, even in the same script,
and can be used in numerical and string type expressions respectively.
Operations resulting in strings CANNOT be used directly as macro names in macro calls,
or as attribute names in material, fill, line type or style definitions.
Variables given a string value will be treated as such and can be used wherever string values are required.
If later in the script the same variable is given a numerical value,
it will be usable in numerical expressions only until it is given a string value again.
Where possible, in the precompilation process the type of the expressions is checked.

GDL supports one and two dimensional arrays. Variables become arrays after a declaration statement, in which their dimensions are specified.

DIM

DIM var1[dim_1], var2[dim_1][dim_2], var3[ ],
        var4[ ][ ], var5[dim_1][ ],
        var5[ ][dim_2]

After the DIM keyword there can be any number of variable names separated by commas.
var1, var2, … are the array names, while the numbers between the brackets represent the dimensions of the array (numerical constants).
Variable expressions cannot be used as dimensions.
If they are missing, the array is declared to be dynamic (one or both dimensions).

Library part parameters can also be arrays. Their actual dimensions are specified in the library part dialog.
Parameter arrays do not have to be declared in the script and they are dynamic by default.
When referencing the library part using a CALL statement, the actual values of an array parameter can be an array with arbitrary dimensions.

The elements of the arrays can be referenced anywhere in the script but if they are variables, only after the declaration.

var1[num_expr] or var1
var2[num_expr1][num_expr2] or var2[num_expr1] or var2

Writing the array name without actual indices means referencing the whole array (or a line of a two-dimensional array)
which is accepted in some cases (CALL, PRINT, LET, PUT, REQUEST, INPUT, OUTPUT, SPLIT statements).
For dynamic arrays there is no limitation for the actual index value. During the interpretation,
when a non-existing dynamic array element is given a value,
the necessary quantity of memory is allocated and the missing elements are all set to 0 (numerical).

Warning! This may cause an unexpected out of memory error in some cases.
Each index – even of a possibly wrong, huge value – is considered valid, since the interpreter is unable to detect the error condition.
A non-existing dynamic array element is 0 (numerical).

Arrays having a fixed dimension are checked for the validity of the actual index on the fixed dimension.
Array variables with fixed length cannot accept dynamic array values in assignments.
However, dynamic arrays that are given whole array values will take on those values.
This also applies to some statements where whole array references can be used as return parameters. (REQUEST, INPUT, SPLIT).

Array elements can be used in any numerical or string expression. They can be given string or numerical values.

Indices start with 1, and any numerical expression can be used as an index.

Array elements can be of different simple types (numerical, string, group).
The type of the whole array (main type) is the type of its first element ([1] or [1][1]).
Parameter and global variable arrays cannot be of mixed type.

VARDIM1

VARDIM1 (expr)

VARDIM2

VARDIM2 (expr)

These functions return as integers the actual dimension values for the (array) expression specified as a parameter.
They must be used if you want to handle correctly all actual elements of a dynamic array or an array parameter.
If no element of a dynamic array was previously set, the return value is 0. For one-dimensional arrays VARDIM2 returns 0.

Example 1:
Examples for numeric expressions:

Z
5.5
(+15)
-x
a*(b+c)
SIN(x+y)*z
a+r*COS(i*d)
5' 4"
SQR (x^2 + y^2) / (1 - d)
a + b * sin (alpha)
height * width

Example 2:
Examples for string expressions:

"Constant string"
name + STR ("%m", i) + "." + ext
string_param <> "Mode 1"

Example 3:
Examples for expressions using array values:

DIM tab[5], tab2[3][4] ! declaration
tab[1] + tab[2]
tab2[2][3] + A
PRINT tab
DIM f1 [5], v1[], v2[][]
v1[3] = 3     ! v1[1] = 0, v1[2] = 0, array of 3 elements
v2[2][3] = 23 ! all other elements(2 X 3) = 0
PRINT v1, v2
DIM f1 [5], v1[], v2[][]
FOR i = 1 TO VARDIM1(f1)
    f1 = i
NEXT i
v1 = f1
v2 [1] = f1
PRINT v1, v2

PARVALUE_DESCRIPTION

 PARVALUE_DESCRIPTION (parname [, ind1 [, ind2]])


This function returns the parameter value description string of a numerical parameter specified using the VALUES command statement.
If no description is specified, the returned value is an empty string.

parname: name of the parameter

ind1, ind2: actual indices if the parameter is an array.