This article covers the following topics:
- Comments
- Multiline Calculations
- Variable Names
- Scalar Variables
- Array Variables
- Matrix Variables
- Ternary Operators
Comments
To create a full line comment, start the line with a hash (#) mark. In the example below the first line is commented out and will not be parsed:
# i is the variable storing I50
i = mean(r0, r1);
( i < 10) ? (1.029 * i - 0.06) : (1.059 * i - 0.37)
Multiline Calculations
Multiple lines are supported for calculations. The last line that is not an assignment or comment is evaluated and returned in the table.
i = 2;
( i < 10) ? (1.029 * i - 0.06) : (1.059 * i - 0.37)
i * 10
In the example above, 20 would be returned.
Variable Names
Variable names can contain letters (both uppercase and lowercase), numbers, underscores, and dollar signs, however, variable names cannot begin with numbers. JavaSript reserved keywords may not be used as variable names.
Variable names must not match any of the names (UIDs) for the Ctp widget, the source activity widget, table meta-items, row meta-items, readings, column calculations, row calculations or table calculations.
In the example above temp, pres, ctp, csa, t0 - t2, m00 - m04, r00 - r04, e00 - e04, e20-e24, and a0 would all be reserved.
Scalar Variables
Scalar variables may be any number. Declaration and assignment are done in a single step as shown below:
s = 10.5;
s
In the example above, 10 is returned.
Array Variables
Array variables may be any number of numbers. Multi-dimensional arrays are also supported. Index numbering starts at 1. Declaration and assignment are done in a single step as shown below:
a = [4, 3.2, 2, 1];
a[2]
In the example above, 3.2 is returned. For a multidimensional array the following syntax is used:
a = [[4, 3, 2, 1], [8, 7, 6, 5]];
a[2, 3]
In the example above, 6 is returned.
Matrix Variables
Matrix variables may be any number of arrays. Index numbering starts at 1. Declaration and assignment are done in a single step as shown below:
m = matrix([[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]);
m[2, 2, 2]
In the example above, 10 is returned.
Ternary Operators
A ternary operation may be used to form a simple if, then, else statement. The expression to the left of the question mark is evaluated. If the expression is true the expression between question mark and the colon is returned. If the expression is false, the expression after the colon is returned.
i = 5;
( i > 10 ) ? ( i * 1.5 ) : ( i * 2 )
In the example above, 7.5 is returned ( i * 1.5 ).
Comments
0 comments
Please sign in to leave a comment.