Lexical format

For those who know about such things,
the datafile and commands are read with a lexical analyzer generated
by the lex program. The specification is in datafile.lex. Commands
are further parsed by a yacc-generated parser.

In parsing an expression, the longest legal expression
is used. This permits coordinates to be specified by
several consecutive expressions with no special
separators.

Comments

Comments may be enclosed in /* */ pairs (as in C) and
may span lines. // indicates the rest of the line is a comment,
as in C++.

Lines and line splicing

The file is made up of lines. Line breaks are significant.
The next physical line can be spliced onto the current
line by having \ be the last character of the current line.
Line splicing is not effective in // comments.
Blank lines and comment lines may be placed freely anywhere.
The various combinations of CR and NL that
various computer systems use are all recognized

Case

Upper and lower case is not significant in the datafile, except in
#define macro names. In run-time commands, case is only
significant
for single-letter commands.

Whitespace

In the datafile, whitespace consists of spaces, tabs, commas, colons,
and semicolons. So it's fine if you want to use commas to
separate coordinate values, and colons to prettify constraint
definitions. In commands, whitespace consists of spaces and tabs.
CTRL-Z is also whitespace, for the benefit of files imported from
DOS.

Identifiers

Identifiers follow standard
C rules (composed of alphanumeric characters and '_'
with the leading character not a digit) and must not
be keywords. Identifiers are used for macro names
(in the datafile) and user-defined
variables and
commands.
Identifiers must have at least two characters,
since single characters can be confused with commands.
To find out if a name is already in use as a keyword or
user-defined name interactively, use
help command. In scripts, one
can use the is_defined function, which has the syntax

is_defined(stringexpr)

The stringexpr must be a quoted string or other string expression.
The return value is 0 if the name is undefined, 1 if defined.
This function is evaluated at run-time, but variables in the whole
command are parsed before the command is executed, so a command
like if is_defined("newvar") then newvar := 1 else newvar := 2
will give newvar the value 1 even if this is its first appearance.
A better way in scripts to test is to use the define
command to define the variable without initialization, and then test to
see if it has the default value, i.e. 0 for a numeric variable and a
sizeof 0 for a string variable.

Numbers

Constant values may be in any of the usual forms. This
includes integers, fixed point, and scientific notation
such as

2 -3 .5 23. 5e-10 +0.7D2

Hexadecimal integers starting with 0x, as in 0x12Af, are also accepted,
as are binary numbers such as 11001b, indicated by a trailing 'b'.
Color names are interpreted as integers.

Colors

The colors of edges
and facets
are recorded as integers in the
range -1 through 15. How these
integers translate to colors on the screen is determined by how
Evolver's graphics drivers are written. The following synonyms are
supplied, and it is hoped that the
graphics drivers will be written to display these correctly:

-1 CLEAR
0 BLACK
1 BLUE
2 GREEN
3 CYAN
4 RED

5 MAGENTA
6 BROWN
7 LIGHTGRAY
8 DARKGRAY
9 LIGHTBLUE
10 LIGHTGREEN

11 LIGHTCYAN
12 LIGHTRED
13 LIGHTMAGENTA
14 YELLOW
15 WHITE

The special color value CLEAR (-1) makes a facet transparent.
"Transparent" is a synonym for clear.

These tokens are simply translated to integer values wherever they
occur, so these are reserved words. Edge and facet colors may be
set in the datafile or by the set command.

Arithmetic expressions

Arithmetic expressions evaluate to real numbers. Boolean expressions
are a subclass, with zero as false and nonzero as true; true results
evaluate as 1. Ordinary algebraic notation is used.

Constant expressions

Constant expressions are evaluated when parsed. They are denoted
by constexpr in various syntax definitions. They occur
mostly in the datafile. Although they may contain variables,
changing the variable value after parsing has no effect.
Variable expressions (denoted by expr
in syntax definitions) are recorded as parse trees and are re-evaluated
each time needed.

Any toggle command
name may be used as a Boolean variable in an
expression (full word toggles, not single letters). But beware the
ambiguity in interpreting a toggle as a command or a value.
You may have to force the toggle to be interpreted as a value.
"ad := autodisplay" sets ad as a command synonym for
autodisplay, while "ad := (autodisplay)" records the
current boolean value.

String expressions

A string expression evaluates to a string of characters. At present,
the only ways to produce strings are:

double-quoted string literals, e.g. "this is a string".
The following standard C escape sequences are recognized:

\n newline

\r carriage return

\t tab

\b backspace

\q double-quote mark

\c the character c elsewise

In DOS, MS-Windows, or Windows NT paths, use / as the directory separator,
since \ is an escape character. DOS and Windows have always accepted
/ as a directory separator.

successive double-quoted strings, which are concatenated into
one string when read.

Arithmetic operators

Usual real arithmetic; +,-,* also work with arrays.
NOTE: A '+' or '-' preceded by
whitespace and followed
by a number is taken to be a signed number. Thus
"3 - 5" and "3-5" are single expressions, but
"3 -5" is not. This is for convenience in separating
multiple expressions listed on the same line for
vertex coordinates, metric components, etc. in the datafile.

Built-in matrix multiplication of arrays. Stores A*B in C. A, B, and
C must be stand-alone 1 or 2 dimensional array variables with appropriately
matching dimensions; in particular, you cannot get a scalar product of
vectors with this, unless you declare A to be 1xN, B to be Nx1, and C to
be 1x1. C must be different from A and B. Does not return a value.
Also doesn't work with array attributes yet. Obsolete, since the * operator
now works with vectors and arrays.

matrix_inverse(A,B)

Built-in matrix inversion of an array. Stores the inverse of A in B. A and
B must be stand-alone 2 dimensional array variables with
matching dimensions. B can be the same as A. Returns a value, 1 for success, 0 for failure
or singular matrix.

matrix_determinant(A)

Built-in matrix determinant of a square array.
Has function syntax, so it returns the value of the determinant.

Miscellaneous functions

IS_DEFINED

To find out if a name is already in use as a keyword or
user-defined name, use the is_defined function, which
has the syntax

IS_DEFINED(stringexpr)

The stringexpr must be a quoted string or other string expression.
The return value is 0 if the name is undefined, 1 if defined.
This function is evaluated at run-time, but variables in the whole
command are parsed before the command is executed, so a command
like if is_defined("newvar") then newvar := 1 else newvar := 2
will give newvar the value 1 even if this is its first appearance.
A better way in scripts to test is to use the define
command to define the variable without initialization, and then test to
see if it has the default value, i.e. 0 for a numeric variable and a
sizeof 0 for a string variable.

SIZEOF

Returns the number of entries in an array or array
extra attribute.
Can also be applied to a string or string variable to get the number
of characters in the string.
Syntax:

SIZEOF(name)
SIZEOF(string)

In the first form, name is the name of the array or extra attribute,
not in quotes.

VALID_BOUNDARY

Boolean function. Returns 1 or 0 depending on whether a parametric
boundary with the given number exists (note that the name of a
named boundary is internally interpreted as a number). Syntax:

VALID_BOUNDARY(expression)

One use is in looping through all parametric boundaries, in conjunction
with the high_boundary internal variable. For example,

VALID_ELEMENT

Boolean function.
Returns 1 or 0 depending on whether an element of a given index
exists. Syntax:

VALID_ELEMENT(indexed_element)

Examples:

if valid_element(edge[12]) then refine edge[12]
if valid_element(body[2]) then set body[2].facet color red

User-defined built-in functions

User-defined functions can be defined in C in userfunc.c, so
you have to be compiling your own Evolver if you want to use these.
They are meant for situations where expression interpretation
is too slow, or functions such as elliptic integrals are
wanted. Currently, they are automatically functions of
the coordinates. Do not give any arguments in the expression;
for example "(usr1 + usr3)/usr10".

Aggregate functions

The maximum, minimum, sum, or average of an expression over a set
of elements may be done with aggregate functions. The syntax is

aggregate(generator,expr)

where aggregate is max, min, sum, or avg,
and generator is an
element generator. Example: this
prints the total area of all green facets:

print sum(facet where color == green, area)

"Count" is an aggregate function that gives the number of elements
generated, regardless of the expression.

Element attribute values in expressions

The value of any
element attribute
may be used in an expression.
The attribute name alone may be used if there is a default element active.
Example:

Variables

The Evolver command language has its own version of the user-defined variables
common to most programming languages. Variables are typed according to
the types of the values assigned to them: numeric or string.
Users may define numeric variables either by
variable declarations in the datafile, or both types by
assigning a value
to an identifier in a command. A variable may be subjected to optimization
by declaring it an
optimizing_parameter in the datafile.

Arrays

It is possible to define multidimensional arrays of integers or reals
with the syntax

DEFINE variablename REAL|INTEGER|STRING [expr]...

This syntax works both in the datafile header and at the command prompt.
If the array already exists, it will be resized, with old elements
kept as far as possible. Do not resize with a different number of
dimensions. Note that array indexing starts at 1. A size of 0 is legal,
and useful if you are not using an array at the moment and want to
free storage space. There is runtime checking of array bounds. Example:

Identifier names declared local
can be used in array declarations in procedures and functions;
dynamic sizes can be used, but static sizes may be a bit faster
since memory doesn't need to be dynamically allocated.

In the top of the datafile, arrays may be initialized with
nested bracket initializers following the definition. For example:

Array initialization syntax works for runtime assignments to
arrays and array slices, including element attributes that
are arrays. The entries in the initializer must be single
numbers, not arrays. The number of dimensions on the left
and right side of the assignment must agree, but the sizes
in each dimension need not agree. Missing elements on the
right side are regarded as zero. Examples:

The right side is evaluated each time the assignment is
executed, so the entries on the right can be any expressions
that evaluate to numbers. Assignment with += and -= also
work, as does *= and /=, but note that all of these
work element-wise (i.e. *= and /= are not matrix multiplication
and division).

The print command
may be used to print whole arrays or array slices
in bracketed form. Example:

print fvalues
print fvalues[4]

There are some basic whole-array operations that permit arrays on
the left side of an assignment statement:

Here "array" on both sides of the assignment means a single whole array;
not an array-producing expression or array slice.
But "scalar" can be any expression that evaluates to a single value.
For multiplication, the arrays must be two-dimensional with properly
matching sizes. These operations also apply to element attributes
that are arrays.

For one-dimensional arrays, the * operator gives the
sum of the product of corresponding entries. Example:

print vertex[1].__velocity * facet[3].__facet_normal

Internal variables

These are pre-defined names for some of Evolver's internal variables.
They may be used in the same way as user-defined variables, except
the values of read-only variables may not be changed by the user.

Internal read-write variable.
When set to a non-zero value, causes the command interpreter
to abort and return to the command prompt. Software equivalent
of hitting the keyboard interrupt (typically CTRL-C). The
break doesn't happen immediately, but at a certain point in
the interpreter loop when it periodically checks for user
interrupt. Meant for bailing out of nested commands, since
return only breaks out
of the current procedure.

Internal read-only variable. Total elapsed Evolver execution
time in seconds. Reads system process elapsed time, which often has
a fairly coarse resolution of 0.01 seconds. For nanosecond timing,
see cpu_counter.

Internal read-write string variable. This is the title that is
displayed on the Evolver command console window. The default value is
"Surface Evolver - datafilename" (with the name of the current datafile, of
course). Useful when you are simultaneously running various instances, and
you want to tell which is running in which console window. Just assigning
a string to console_title automatically changes the title on the window.

Internal read-write variable. When vertices are
projected to
level-set constraints,
projection by Newton's method
is repeated until the level-set function is smaller than constraint_tolerance.
Default value 1e-12.

Internal read-only variable. Processor cycle counter, available
only on systems I know how to access this (x86 for now). Gives the number
of CPU cycles since the system booted. Note that this is wall clock time,
not process time. Also note that it resets to zero when a computer
hibernates, so it is not guaranteed to be monotone increasing during the
life of a process! Also, multiple processors in a machine may not have
identical CPU counters, so the Evolver process should be assigned to
a particular processor (in Windows, this may be done in Task Manager
by setting the process "affinity" in its properties).
For process elapsed time,
see clock.

Internal read-write vector. For a torus mode surface,
if clipped mode is in effect, the center of the clip box is
set with this array, whose dimension is the dimension of
the ambient space. This array does not exist by default,
it has to be created by the user.
Details.

Internal read-only variable. Number of edges deleted by
delete command.
This does not count the secondary edge deletions caused by deleting
an edge.
Prints and resets to 0 at the end of a command execution, or when
flush_counts is done.
Also reset by reset_counts.

Internal read-write string variable.
This is the title that is
displayed on the Evolver graphics window. The default value is
the datafile name. Useful when you are simultaneously running various instances, and
you want to tell which is running in which graphics window. Just assigning
a string to graphics_title automatically changes the title on the window.
There are also graphics_title2 and graphics_title3 variables if you
have a second or third graphics window.

Internal read-write variable. Magnitude regarded as zero by
hessian command when factoring
the Hessian matrix. If a zero appears on the diagonal at the pivot
during factoring, a check is made to see if the rest of the row is zero.
If it is, then a 1 is placed on the diagonal; else an error is reported.

Internal read-write variable.
Hessian commands treat vertices whose normal
vector is nearly perpendicular
to constraints as fixed. hessian_slant_cutoff is the cosine
of angle. Works on vertices with one degree of freedom in
hessian_normal mode. Default value 0.

Internal read-only variable giving the number of the highest
parametric boundary defined. Remember that the name of a named
boundary is internally interpreted as a number, and that boundary
may be referred to by that number. Useful in iterating through
all boundaries, for example

Internal read-only variable giving the number of the highest
level-set constraint. Remember that the name of a named
constraint is internally interpreted as a number, and that constraint
may be referred to by that number. Useful in iterating through
all constraints, for example

Internal read-only variable. Inverse matrix of the
torus_periods matrix. Uses 1-based indexes.
Useful for normalizing vertex coordinates to period basis.
The syntax for calculating the period basis coordinates would be like

Internal read-only variable. Number of edges flipped to triangles by
the pop_edge_to_tri command.
Prints and resets to 0 at the end of a command execution, or when
flush_counts is done.
Also reset by reset_counts.

Internal read-only variable. Number of quadrilaterals flipped by
the pop_quad_to_quad command.
Prints and resets to 0 at the end of a command execution, or when
flush_counts is done.
Also reset by reset_counts.

Internal read-only variable. Number of triangles flipped to edges by
the pop_tri_to_edge command.
Prints and resets to 0 at the end of a command execution, or when
flush_counts is done.
Also reset by reset_counts.

Internal read-write variable. Seed for random number
generator, used for example in jiggling
or in finding random initial vectors in various
Hessian eigenvector algorithms.
Defaults to 1 at start of datafile.

Internal read-write variable.
In the quadratic model,
the smoothness of graphing of curved quadratic edges can be
controlled with the internal variable
string_curve_tolerance,
which is the desired angle in degrees between successive graphed segments
making up the edge.

Internal read-write variable.
When volume constraints
or named quantity
constraints are enforced,
Newton's method is repeated until the total deviation from target values
is less than target_tolerance. Default value 1e-4.

Internal read-only variable.
Thickness for thickened surfaces in graphics output in
P command. Used when facet
frontcolor and
backcolor are different.
Default value 0.001 times the maximum linear dimension of the surface.
If you get backside color showing through,
increase the thickness.

Internal read-only variable. Current values of the period vectors in the
torus model. Torus_periods[i][j]
is component j of vector i. Uses 1 based indexes.
For changing the torus_periods, define the
periods in the datafile with variables, and alter the variables.

Internal read-only variable. Total area of the surface
in soapfilm or
simplex models.
Beware that this is not continuously updated with every
change in the surface, but rather upon return to the command prompt. If
a script needs the current total_area recalculated, it should do the
"recalc" command before using total_area.

Internal read-only variable. Total energy of the surface.
Beware that this is not continuously updated with every
change in the surface, but rather upon return to the command prompt. If
a script needs the current total_energy recalculated, it should do the
"recalc" command before using total_energy.

Internal read-write variable. The ratio of the the vertical to
horizontal dimensions of the display window. If set, this locks the
aspect ratio to the given value. The window may be resized with the
mouse, but the aspect ratio will stay the same. The unset value of
window_aspect_ratio is 0; setting window_aspect_ratio to 0 will
unlock the aspect ratio. Applies also to the PostScript bounding box,
if full_bounding_box is on.
Currently implemented only in Evolver with GLUT graphics.
Caveat: the window doesn't always fully follow the mouse; just keep trying.