Trelis 16.4 User Documentation
Several mathematical, Trelis and string functions are implemented in APREPRO.
To cause a function to be used, you enter the name of the function followed by a list of zero or more arguments in parentheses. For example
sqrt(min(a,b*3))
uses the two functions sqrt() and min(). The arguments a and b*3 are passed to min(). The result is then passed as an argument to sqrt(). The functions in APREPRO are listed below along with the number of arguments and a short description of their effect.
The following mathematical functions are available in APREPRO. Check current APREPRO documentation for any updates to this list of functions.
Table 1. Mathematical Functions
Syntax |
Description |
|||
abs(x) |
Calculates the absolute value of x. |x| |
|||
acos(x) |
Calculates the inverse cosine of x, returns radians |
|||
acosd(x) |
Calculates the inverse cosine of x, returns degrees |
|||
acosh(x) |
Calculates the inverse hyperbolic cosine of x |
|||
asin(x) |
Calculates the inverse sine of x, returns radians |
|||
asind(x) |
Calculates the inverse sine of x, returns degrees |
|||
asinh(x) |
Calculates the inverse hyperbolic sine of x |
|||
atan(x) |
Calculates the inverse tangent of x, returns radians |
|||
atan2(y,x) |
Calculates the inverse tangent of y/x, returns radians |
|||
atan2d(y,x) |
Calculates the inverse tangent of y/x, returns degrees |
|||
atand(x) |
Calculates the inverse tangent of x, returns degrees |
|||
atanh(x) |
Calculates the inverse hyperbolic tangent of x |
|||
ceil(x) |
Calculates the smallest integer not less than x |
|||
cos(x) |
Calculates the cosine of x, with x in radians |
|||
cosd(x) |
Calculates the cosine of x, with x in degrees |
|||
cosh(x) |
Calculates the hyperbolic cosine of x |
|||
d2r(x) |
Converts degrees to radians. |
|||
dim(x,y) |
Calculates x - min(x,y). |
|||
dist(x_{1},y_{1}, x_{2},y_{2}) |
Calculates distance from x_{1},y_{1} to x_{2},y_{2} |
|||
exp(x) |
Calculates e^{x} (Exponential) |
|||
floor(x) |
Calculates the largest integer not greater than x. |
|||
fmod(x,y) |
Calculates the floating-point remainder of x/y. |
|||
hypot(x,y) |
Calculates sqrt(x^{2}+y^{2}) |
|||
int(x), [x] |
Calculates the integer part of x truncated toward 0. |
|||
julday(mm, dd, yy) |
Calculates the Julian day corresponding to mm/dd/yy. |
|||
juldayhms (mm, dd, yy, hh, mm, ss) |
Calculates the Julian day corresponding to mm/dd/yy at hh:mm:ss |
|||
lgamma(x) |
Calculates log(G(x)) |
|||
ln(x), log(x) |
Calculates the natural (base e) logarithm of x. |
|||
log1p(x) |
Calculates log(1+x) |
|||
log10(x) |
Calculates the base 10 logarithm of x. |
|||
max(x,y) |
Calculates the maximum of x and y. |
|||
min(x,y) |
Calculates the minimum of x and y. |
|||
polarX(r,a) |
Calculates r ´ cos(a), a is in degrees |
|||
polarY(r,a) |
Calculates r ´ sin(a), a is in degrees |
|||
r2d(x) |
Converts radians to degrees. |
|||
rand(xl,xh) |
Calculates a random number between xl and xh. |
|||
sign(x,y) |
Calculates x ´ sgn(y) |
|||
sin(x) |
Calculates the sine of x, with x in radians. |
|||
sind(x) |
Calculates the sine of x, with x in degrees. |
|||
sinh(x) |
Calculates the hyperbolic sine of x |
|||
sqrt(x) |
Calculates the square root of x. |
|||
tan(x) |
Calculates the tangent of x, with x in radians. |
|||
tand(x) |
Calculates the tangent of x, with x in degrees. |
|||
tanh(x) |
Calculates the hyperbolic tangent of x. |
|||
Vangle(x1,y1, x2,y2) |
Calculates the angle between the vector x_{1}i + y_{1}j and x_{2}i + y_{2}j. Returns radians. |
|||
Vangled(x1,y1, x2,y2) |
Calculates the angle between the vector x_{1}i + y_{1}j and x_{2}i + y_{2}j. Returns degrees. |
The following Trelis Functions are available:
Table 2. Trelis Functions
A few useful string functions are available:
Table 3. String Functions
Syntax |
Description |
|||
tolower(svar) |
Translates all uppercase characters in svar to lowercase. It modifies svar and returns the resulting string. |
|||
toupper(svar) |
Translates all lowercase character in svar to uppercase. It modifies svar and returns the resulting string. |
|||
execute(svar) |
svar is parsed and executed as if it were a line read from the input file. For example, if svar="b=sqrt(25.0)", then returns the value 5 and sets b = 5. The expression svar is enclosed in delimiters prior to being executed, and it must be a valid expression or an error message will be printed. |
|||
rescan(svar) |
Similar to execute(svar), except that svar is not enclosed in delimiters prior to being executed. For example, if svar = "Create Vertex
{1+5} {sqrt(5)} {sqrt(6)}", then would print: Create Vertex 6 2.236067977 2.449489743. The difference between execute(sv1) and rescan(sv2) is that sv1 must be a valid expression, but sv2 can contain zero or more expressions. |
|||
getenv(svar) |
Returns a string containing the value of the environment variable svar. If the environment variable is not defined, an empty string is returned. |
|||
get_word(n,svar,del) |
Returns a string containing the nth word of svar. The words are separated by one or more of the characters in the string variable del |
|||
word_count(svar,del) |
Returns the number of words in svar. Words are separated by one or more of the characters in the string variable del |
|||
strtod(svar) |
Returns a double-precision floating-point number equal to the value represented by the character string pointed to by svar. |
|||
Print(msg) | Prints msg | |||
PrintError(svar) | Outputs the string svar to stderr. | |||
error(svar) | Outputs the string svar to stderr and then terminates the code with an error exit status | |||
Quote(svar) | Returns the string svar, enclosed in single quotes. | |||
TimerStart() | Starts the CPU timer | |||
TimerStop() | Stops the CPU timer | |||
Type(entity name) | Returns the type of the entity with the given name | |||
Units(svar) | Sets variables useful for working in a unit system. See APREPRO Units. |
The following example shows the use of some of the string functions.
#{t1 = "ATAN2"} {t2 = "(0, -1)"}
#{t3 = tolower(t1//t2)}
...The variable t3 is equal to the string atan2(0, -1)
#{execute(t3)}
...t3 = 3.141592654
The result is the same as executing {atan2(0, -1)}
This is admittedly a very contrived example; however, it does illustrate the workings of several of the functions. In the first example, an expression is constructed by concatenating two strings together and converting the resulting string to lowercase. This string is then executed.
The following example uses the rescan function to illustrate a basic macro capability in APREPRO. The example creates vertices in Trelis equally spaced about the circumference of a 180 degree arc of radius 10. Note that the macro is 5 lines long (3 of the lines start with #, with the exception of the looping constructs - the actual journal file for this would not continue lines but would put each one on one long line).
#{num = 0} {rad = 10} {nintv = 10} {nloop = nintv + 1}
#{line = 'Create Vertex {polarX(rad, (++num-1) * 180/nintv)} {polarY(rad, (num-1) * 180/nintv)}'}
#{loop(nloop)}
#{rescan(line)}
#{endloop}
Output:
Create Vertex 10 0
Create Vertex 9.510565163 3.090169944
Create Vertex 8.090169944 5.877852523
Create Vertex 5.877852523 8.090169944
Create Vertex 3.090169944 9.510565163
Create Vertex 6.123233765e-16 10
Create Vertex -3.090169944 9.510565163
Create Vertex -5.877852523 8.090169944
Create Vertex -8.090169944 5.877852523
Create Vertex -9.510565163 3.090169944
Create Vertex -10 1.224646753e-15
Note the loop construct to automatically repeat the rescan line. To modify this example to calculate the coordinates of 101 points rather than eleven, the only change necessary would be to set {nintv=100}.