Operators and Functions
In this topic:
Key to abbreviated unit options
General Information
A line beginning with * is ignored.
The return value is the last line that gives a value without assigning it to a variable.
* Not the return value
myVar = Min(1, 2)
* Not the return value
anotherVar = "someString"
* The return value
substring(anotherVar, 1, 4)
Can create and use variables by doing the following:
myVar = 5
Min(3, myVar)
Note: Variables are not case sensitive.
if/else
flow control is available.
myVar = 4.5
if (myVar lt 4) then
"myVar is 4"
elseif (myVar gt 5) then
"myVar is greater than 5"
else
"myVar is between 4 and 5"
endif
TRUE is signified by the value 1.
FALSE is signified by the value 0.
Format
Conditions are entered in the format:
<variable><operator><value>
where
<variable> |
The name of the block model variable (upper or lower case), or the number of a mapfile variable. Note: Mapfile variables must be preceded by a $ (dollar sign). |
<operator> |
A symbol or textual operator (see below). |
<value> |
A numeric or alphanumeric value. Note: Alphanumeric values must be in quotes, for example 'ABC1'. We also recommend that variable names do not contain symbols except for underscores (for example CU_IVD is okay but not CU%). |
Assigning Variables
Use the assignment operator = to assign a value to a variable. Use logical operators for conditional statements.
Assignment operator:
AU = 1.0
sets the value of
AU
to '
1.0
'.
Logical operator:
AU EQ 1.0
select
AU
if value is equal to '
1.0
' (logical operator).
Expression Functions
Arithmetic Operators
+ addition - subtraction * multiplication / division ~ exponentiation
Logical Operators
Logical functions have the same syntax as numeric functions. They return the value 1 (one) for TRUE and 0 (zero) for FALSE. Currently the only logical function is
MATCH
, which takes a wildcard pattern and a string to be matched against the pattern as arguments (that is
MATCH(pattern, string
))
. The wildcards (* multi-character and % single character) are supported.
Logical operators are not distinguishable from numeric operators. The values TRUE and FALSE are represented by "not zero" and "zero". Logical expressions and functions always return the value one for TRUE. It is often useful to mix logical operators and arithmetic operators.
(STR EQS "A") + (STR EQS "B") * 2
returns
'
0
' if
STR
is not equal to '
A
' or '
B
'
OR
'
1
' if
STR
equals '
A
'
OR
'
2
' if
STR
equals '
B
'
Operator |
Example |
Result |
Comments |
---|---|---|---|
and |
3 eq 3 and 3 eq 4 |
0 |
Used to combine a list of two or more arguments. Arguments are used to evaluate an object. Returns true (1) if an object matches all arguments or false (0) if an object does not match all arguments. |
or |
3 eq 3 or 3 eq 4 |
1 |
Used to combine a list of two or more arguments. Arguments are used to evaluate an |
xor |
3 eq 3 xor 4 eq 4 |
0 |
Returns true (1) if only one of the statements is true. Returns false (0) if neither of the statements is true or if both of the statements is true. When more than two statements are used, the logic is more complex. For example: 3 eq 3 xor 3 eq 4 xor 4 eq 4 would return false. Why? The operation evaluates from left to right. 3 eq 3 xor 3 eq 4 = true because only one of those statements is true. Now the equation is: true xor 4 eq 4. Both of these statements is also true, which would result in a "false" return. Therefore, the return for the entire statement (3 eq 3 xor 3 eq 4 xor 4 eq 4) would be false. |
not |
not (3 eq 3) |
0 |
Used as an exclusionary statement for one or more arguments contained in parenthesis. Returns true (1) if the an object fails to meet the argument in the parenthesis. Returns false (0) if an object meets the argument in the parenthesis. |
eq |
3 eq 3 |
1 |
Numeric "is equal" |
ne |
3 ne 3 |
0 |
Numeric "is not equal" |
gt |
4 gt 3 |
1 |
Numeric "is greater than" |
lt |
4 lt 4 |
0 |
Numeric "is less than" |
ge |
4 ge 3 |
1 |
Numeric "is greater than or equal to" |
le |
4 le 4 |
1 |
Numeric "is less than or equal to" |
eqs |
"au" eqs "au" |
1 |
String "is equal" |
nes |
"au" nes "au" |
0 |
String "is not equal" |
gts |
"10" gts "09" |
1 |
String "is greater than" |
lts |
"au" lts "au" |
0 |
String "is less than" |
ges |
"10" ges "09" |
1 |
String "is greater than or equal to" |
les |
"au" les "br" |
1 |
String "is less than or equal to" |
Numeric Functions
Numeric functions must be specified in the format:
FUNCTION (arg1, arg2, arg3,...)
where the list of function arguments are enclosed in brackets directly following the function name.
Function |
Example |
Result |
Comments |
---|---|---|---|
ln |
ln(2) |
0.693147 |
Natural log of supplied number. |
exp |
exp(2) |
7.389056 |
Power of Euler's number |
log |
log(2) |
0.30103 |
Log base 10 of supplied number. |
sin |
sin(3.141593) |
0 |
Returns the sine of an angle specified in radians. |
cos |
cos(3.141593) |
-1 |
Returns the cosine of an angle specified in radians. |
tan |
tan(0.785398) |
1 |
Returns the tangent of an angle specified in radians. |
asin |
asin(0) |
0 |
Arc sine of the supplied value. Result is angle in radians. |
acos |
acos(0) |
1.5708 |
Arc cosine of the supplied value. Result is angle in radians. radians = degrees(π/180); degrees = radians(180/π) |
atan |
atan(1) |
0.785398 |
Arc tangent of the supplied value. Result is angle in radians. |
sqrt |
sqrt(16) |
4 |
Square root of the entered value |
int |
int(1.9) |
1 |
Remove decimals from the entered value. This does not round; it truncates. |
frac |
frac(1.9) |
0.9 |
Return only the decimal portion of the entered value. |
abs |
abs(-5) |
5 |
Absolute value of the entered number. |
sgn |
sgn(-8) |
-1 |
Sign (positive, negative, neither) |
mod |
mod(1.1, 0.2) |
0.1 |
Modulus, which returns a remainder that results when one number is divided by another. Example 1: mod(8,4) returns 0 because 8/4 = 2 with no remainder Example 2: mod (12,16) returns 12 because 12/16 = 0 with 12 as the remainder. |
max |
max(1.1, 0.2) |
1.1 |
Return the maximum value of supplied values. |
min |
min(1.1, 0.2) |
0.2 |
Return the minimal value of supplied values. |
round |
round(123.456, 2) |
123.46 |
Round a value to specified number of decimal places. (<value>, <number of decimal places>) |
& |
"au" & "G1" |
"auG1" |
String concatenation |
String Functions
String functions have the same syntax as numeric functions but return string values.
String constants must be enclosed in either single or double quotes.
if (au lt 2.0) then if (topo eqs "oxide") then oretp = 4.0 else oretp = 3.0. endif endif
The only string operator supported is the string concatenation operator '
&
'.
Function |
Example |
Result |
Comments |
---|---|---|---|
match |
match("a*1%34", "aBcD1234") |
1 |
Returns 1 if the two input character strings match 0 if they do not. Use * as a wildcard representing any series of characters; % as a wildcard representing a any single character |
upcase |
upcase("aBcD1234") |
"ABCD1234" |
Replaces all alpha characters in the input character string with capital letters. |
lowcase |
lowcase("aBcD1234") |
"abcd1234" |
Replaces all alpha characters in the input character string with lower case letters. |
ljust |
ljust(" aBcD1234 ") |
"aBcD1234 " |
Removes any spaces on the left of an input character string. |
rjust |
rjust(" aBcD1234 ") |
" aBcD1234" |
Removes any spaces on the right of an input character string. |
pack |
pack(" aBc D1 234 ") |
"aBcD1234" |
Removes all spaces in the input character string. |
substring |
substring("aBcD1234", 2, 5) |
"BcD1" |
Returns a substring from the input character string. The first number denotes the position in the input character string of the first character of the substring. The second number denotes the position in the input character string of the final character of the substring. |
subleft |
subleft("aBcD1234", 3) |
"aBc" |
Returns the leftmost characters of an input character string. The number specifies how many character positions will be returned. In this example, the leftmost 3 characters of the input character string are returned. |
subright |
subright("aBcD1234", 5) |
"D1234" |
Returns the rightmost characters of an input character string. The |
stringlen |
stringlen("aBcD1234") |
"8" |
Returns the length of a string. |
indexsplit |
indexsplit("aB_cD_1234","_",2) |
"cD" |
iINDEXSPLIT([ATT:Activity Name], "_", 2) where the underscore is the split string to use. Numbers start at 1 for which part to pull out. If you had a string like: Z01_5555_DEC_01_C the above formula would return 5555 |
format |
format(32, "I3") |
" 32" |
See Fortran format documentation . |
Object Functions
Function |
Example |
Result |
---|---|---|
ObjColour |
ObjColour() |
Reports the position that the object's colour occupies on the colour palette. |
ObjDescription |
ObjDescription() |
Reports the object description. |
ObjFeature |
ObjFeature() |
Reports the feature code. |
ObjGroup |
ObjGroup() |
Reports the group the object is in. |
ObjLayer |
ObjLayer() |
Reports the layer the object is in. |
ObjName |
ObjName() |
Reports the object name. |
ObjMeta |
ObjMeta(fieldname) |
Reports the value of fieldname in the object's metadata. |
ObjPrimitive |
ObjPrimitive() |
Reports the name of the predefined primitive shape saved as an attribute of the object. The name of all primitive shapes can be viewed here: $VULCAN/bin/flib/mtkprimitives.pgd |
ObjValue |
ObjValue() |
Reports the value saved to the object's attributes. |
ObjAttr |
ObjAttr("template_name", "attribute_name") |
This function retrieves the value of a specific attribute in the object. |
Polyline Functions
Function |
Example |
Result |
---|---|---|
NumPoints |
NumPoints() |
Returns the number of points in the object. |
GetX |
GetX(2) |
Returns the x-value of the entered point in the object. The given example would return the x-value of the second point in the object. Label point sequence in Vulcan to determine point numbers. |
GetY |
GetY(2) |
Returns the y-value of the entered point in the object. The given example would return the y-value of the second point in the object. Label point sequence in Vulcan to determine point numbers. |
GetZ |
GetZ(2) |
Returns the z-value of the entered point in the object. The given example would return the z-value of the second point in the object. Label point sequence in Vulcan to determine point numbers. |
MinX |
MinX() |
Queries all the points in the object, and returns the lowest x-value found on any point. |
MinY |
MinY() |
Queries all the points in the object, and returns the lowest y-value found on any point. |
MinZ |
MinZ() |
Queries all the points in the object, and returns the lowest z-value found on any point. |
MaxX |
MaxX() |
Queries all the points in the object, and returns the highest x-value found on any point. |
MaxY |
MaxY() |
Queries all the points in the object, and returns the highest y-value found on any point. |
MaxZ |
MaxZ() |
Queries all the points in the object, and returns the highest z-value found on any point. |
AvgX |
AvgX() |
Returns the average x-value of all points in the object. |
AvgY |
AvgY() |
Returns the average y-value of all points in the object. |
AvgZ |
AvgZ() |
Returns the average z-value of all points in the object. |
DeltaX |
DeltaX(1, NumPoints()) |
Returns the change in x between two entered points. The given example would return the change in x between the first and last points in an object. Label point sequence in Vulcan to determine the location of the first and last points in an object. |
DeltaY |
DeltaY(2, 5) |
Returns the change in y between two entered points. Label point sequence in Vulcan to determine point numbers. |
DeltaZ |
DeltaZ(1, 2) |
Returns the change in z between two entered points. Label point sequence in Vulcan to determine point numbers. |
Bearing |
Bearing(1, 3, "rad") |
Returns the bearing between two entered points. Label point sequence in Vulcan to obtain point numbers. The third entry specifies the unit of measure used to report the bearing: "rad" for radians, "dd" for decimal degrees, "dms" for degrees,minutes,seconds |
Gradient |
Gradient(1, 3, "deg") |
Returns the gradient between two entered points. Label point sequence in Vulcan to obtain point numbers. The third entry specifies the unit of measure used to report the gradient: "per" for percentage, "deg" for degrees, "grd" for gradians, "rto" for ratio |
PolyClosed |
PolyClosed() |
Checks for object closure as defined by the Close flag. Returns 1 if TRUE, 0 if FALSE. Example syntax: if (PolyClosed() eq 1) then PolyArea("ac",1) else PolyLength("km",1) endif |
PolyLength |
PolyLength() PolyLength("km",1) |
The first example with empty brackets will return the length of an object in the default coordinate units specified in the project file (DG1). If one of the distance unit options is entered in the brackets, the statement will determine the default coordinate units from the DG1 file, and then convert the default units to the distance units entered. In the given example, the units would be converted to kilometres. Distance unit options: "cm", "m", "km", "ft", "yd", "mi". The distance unit options must always be followed by ',1'. |
PolyArea |
PolyArea() PolyArea("ac",1) |
The first example with empty brackets will return the area of a polygon in the default coordinate units specified in the project file (DG1). So if your default is meters the expression will return square meters. If one of the area unit options is entered in the brackets, the statement will determine the default coordinate units from the DG1 file and then convert to the area unit entered. In the given example, the design area units would be converted to acres. Area unit options: "cm", "m", "km", "ha", "ft", "yd", "mi", "ac". The distance unit options must always be followed by ',1'. |
PolyVolume |
PolyVolume(20, "acft",1) |
The first example with a number in the brackets will return the volume of a polygon assuming that the polygon is projected 20 units. Returning the volume in the default coordinate units specified in the project file (DG1). So if your default is meters the expression will return cubic meters. If one of the volume unit options is entered in the brackets, the statement will determine the default coordinate units from the DG1 file and then convert to the volume unit entered. In the given example, the polygon would be projected at 20 units and a volume would be calculated. The result would be converted to acre feet. If the polygon does not occupy a single plane, a best fit plane will be used for the projection. Volume unit options: "cm", "m", "km", "ft", "yd", "acft". The distance unit options must always be followed by ',1'. |
PolyTons |
PolyTons("bmodel.bmf", "-X -bm 0 500 0 500 0 500", "density", 1.8, 20, "top") |
Procedure:
Argument Entries:
This function can only be used on closed polygons. |
PolyGrade |
PolyGrade("bmodel.bmf", "", "au", 0, "wbm", "density", 1.8, 20, "bot") |
First, a triangulation is created from the polyline, the given thickness, and the given alignment This function can only be used on closed polygons. |
PrimHeight |
PrimHeight() |
|
PrimWidth |
PrimWidth() |
|
PrimArea |
PrimArea("ha") |
The first example with empty brackets will return the cross sectional area of the primitive in the default coordinate units specified in the project file (DG1). So if your default is meters the expression will return square meters. If one of the area unit options is entered in the brackets, the statement will determine the default coordinate units from the DG1 file and then convert to the area unit entered. In the given example, the design area units would be converted to acres. Area unit options: "cm", "m", "km", "ha", "ft", "yd", "mi", "ac". The distance unit options must always be followed by ',1'. |
PrimVolume |
PrimVolume("ft") |
The first example with empty brackets will return the volume of the primitive, based on primitive area multiplies by the object length, in the default coordinate units specified in the project file (DG1). So if your default is meters the expression will return cubic meters. If one of the volume unit options is entered in the brackets, the statement will determine the default coordinate units from the DG1 file and then convert to the volume unit entered. In the given example the result would be converted to feet. Volume unit options: "cm", "m", "km", "ft", "yd", "acft". The distance unit options must always be followed by ',1'. |
PrimTons |
PrimTons("bmodel.bmf", "", "density", 1.8, "MTKPRIM11", "mid", 10, 10) |
First, a triangulation is created from the polyline and either: |
PrimGrade |
PrimGrade("bmodel.bmf", "-X -C 'au ge 0.5' ", "au", 0, "wbv", "density", 1.8) |
First, a triangulation is created from the polyline and either: |
Date and time functions
Function | Example |
Description |
---|---|---|
incrementdatebyday | incrementdatebyday("2021/1/2", 5) -> "2021/1/7" |
Returns a string with date incremented by the specified number of days. A negative number will decrement the date by the number of days provided. |
incrementdatebymonth | incrementdatebymonth("2021/1/2", 4) -> "2021/5/2" |
Returns a string with date incremented by the specified number of months. A negative number will decrement the date by the number of days provided. |
dayofweek | dayofweek("2021/5/11") -> "Tuesday" |
Returns a string with the day of the week date for a given date. Days of the week are returned in English. |
datevalue | datevalue("2021/3/25") -> 44279 |
Returns the number of days between 1900/1/1 and the specified date. |
datetext | datetext(44280) -> "2021/3/26" |
Creates a date from an integer that represents the number of days after 1900/1/1. |
daysbetween |
daysbetween("2000/1/4", "2000/1/1") -> -3 |
Gets the number of days between two specified dates. |
getyear | getyear("2021/1/2") -> 2021 |
Returns the year component of a specified date. |
getmonth | getmonth("2021/1/2") -> 1 |
Returns the month component of a specified date. |
getday | getday("2021/1/2") -> 2 |
Returns the day of month component of a specified date. |
setdate | setdate(2021, 1, 2) -> "2021/1/2" |
Returns a valid date string from the parameters provided in Year, Month, Day entries. |
datetoday | datetoday() -> "2021/3/26" |
Gets the current date. |
Key to abbreviated unit options
"cm" |
Centimetres |
"m" |
Metres |
"km" |
Kilometres |
"ha" |
Hectares (only used in area calculations) |
"ft" |
Feet |
"yd" |
Yards |
"ac" |
Acres (only used in area calculations) |
"acft" |
Acre-feet (only used in volume calculations) |
"mi" |
Miles (only used in length and area calculations) |
Related topics
Tutorial
Templated Attributes tutorial