Expressions


Contents Summary

Detailed Contents
Introduction
Command Line
File Format
Plot Instructions
Expressions
Curve Fitting
Three-Dimensional Plots
PostScript Files
Appendix: Line Styles
Index


5 Expressions

Evaluation of expressions is central to the use of DigiPlot. The coordinates to be plotted are determined by evaluating the expressions indicated by the X and Y plot instructions (or X, Y and Z for three-dimensional plots). The intensity used is given by the expression indicated by the I instruction (or one of its variants), and expressions are used in the curve fitting (see next section, section 6 ) and expression plotting (E) facilities.

The simplest form of expression is a simple constant. This form will often be used for the intensity plot instruction (e.g. I 128) where each piece of data is to be plotted in the same colour. Typically more complex expressions will be required to specify the x and y coordinates in terms of the columns of data. These expressions may involve constants, column references, DigImage variables, binary operators and functions.

Columns are referenced by a [ character followed by an integer indicating which column is to be used. The first column is column 1. There should not be any spaces between the [ and the column number. DigImage variables may be used when specifying a column number. The DigImage variable is substituted before the [ character is processed. For example, if !!a contains the value 3, then [!!a will be converted to [3 when the line containing the expression is processed. Note that if the value of !!a is subsequently changed, the column number will remain unchanged.

In addition to the columns explicitly given in the plot file or data file, DigiPlot has a number of implicit columns as detailed below:

Column reference Description
[1 to [100 Reference to normal data column for the current data input line
[101 to [200 Refers to data columns [1 to [100 for the previous input line
[0 Returns the ordinal position of the point since the last N or N3 plot instruction, starting at zero for the first data line and increasing by one for each data line read. Note that one is added even if the point is not plotted due to failing the PC ... conditional plotting criteria.
[-1 As for [0 except that increased by one only for each piece of data actually plotted.
[-2 The value of x for the last point plotted.
[-3 The value of y for the last point plotted.
[-4 The value of z for the last point plotted.
[-5 The result of the intensity expression for the last point plotted.

An example of the use of these implicit columns is if X [2/3 is the expression being plotted for x, then PC [-2 <> ([2/3) would remove any consecutive duplicate x data. Alternatively, PC [2 <> [102 could be used to achieve the same result.

DigiPlot understands the same set of operators and functions as DigImage. Specifically:

Operator or function ExampleUse
+ 3.1 + [2 Addition
- -[6 - [3 Negative or subtraction
* 4 * [9 Multiplication
/ [3/[!!c Division
^ [1 ^ 2 Exponentation
& [2 & 255 Bit-wise AND of integer part
$ [7 $ 15 Bit-wise Exclusive OR of integer part
% [1 % 1 Bit-wise OR of integer part
AND Logical AND of integer part.
EOR Logical eXclusive OR of integer part.
OR Logical OR of integer part
MOD 3 MOD 2 Modulo arithmetic. A MOD B is equivalent to the Fortran MOD(A,B).
(..) 3 * ([2 - [1) Brackets: evaluate enclosed sub-expression first. May be nested up to ten levels
LOG(..) LOG(1 + [5) Evaluate logarithm base 10 of enclosed sub-expression
LN(..) LN([7 - [!!c) Evaluate natural logarithm of enclosed sub-expression
EXP(..) EXP(-[4^2) Exponential function of enclosed sub-expression
SQRT(..) SQRT(2.0*[5) Square root of enclosed sub-expression
SIN(..) SIN(3.1415*[3) Sine of enclosed sub-expression (angle in radians)
COS(..) COS([1)^2 Cosine of enclosed sub-expression (angle in radians)
TAN(..) TAN([2 + [13) Tangent of enclosed sub-expression (angle in radians)
ASIN(..) ASIN(!!Gt) Arcsine (inverse sine) of enclosed sub-expression (returns angle in radians)
ACOS(..) ACOS([1^2) Arccosine (inverse cosine) of enclosed sub-expression (returns angle in radians)
ATAN(..) TAN([1/[2) Arctangent (inverse tangent) of enclosed sub-expression (returns angle in radians)
SINH(..) SINH(5*[10) Hyperbolic sine of enclosed sub-expression
COSH(..) COSH([1/3) Hyperbolic cosine of enclosed sub-expression
TANH(..) TANH([15) Hyperbolic tangent of enclosed sub-expression
ABS(..) ABS([7 - [6) Absolute value of enclosed sub-expression
SGN(..) 1 + SGN([4) Sign of enclosed sub-expression. Returns 1 if greater than zero, -1 if less than zero or 0 if equal to zero
NOT(..) NOT([1) Logical NOT of integer part of enclosed sub-expression

At present DigiPlot and DigImage do not understand operator precedence. Instead expressions are evaluated from left to right, although sub-expressions enclosed in brackets are evaluated before combining the result with the remainder of the expression. For example the expression

3 + 4*2

would evaluate to 14, whereas mathematical convention gives the answer as 11. It is thus necessary either to rearrange the expression as

4*2 + 3

or to use brackets to group the terms which are to be combined first, viz.

3 + (4*2)

As operator precedence may be introduced with future versions of DigImage and DigiPlot, we strongly recommend that you do not rely on the left-to-right evaluation, but instead group your terms using brackets to synthesise conventional operator precedence. Brackets may be nested up to ten levels deep.

Note that functions are treated as a special form of brackets: after evaluating the enclosed sub-expression, the result is transformed by the specified function. Like brackets, functions may be nested (e.g. SIN(EXP([3 + LN([6)))), the nesting limit again being ten levels (normal brackets are included in this limit).

Goto next document (CurveFitting)


Links

DIGIPLOT

Contents
Index

OTHER

DigImage documentation page
DigImage home page
Stuart Dalziel's home page


Stuart Dalziel, last page update: 21 June 1999