APREPRO Functions

Several mathematical, CUBIT 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.

1. Mathematical Functions

The following mathematical functions are available in APREPRO.

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(x)

Calculates the inverse tangent of x, returns degrees

atand(y,x)

Calculates the inverse tangent of y/x, returns degrees

atanh(x)

Calculates the inverse hyperbolic tangent of x

ceil(x)

Calculates the smallest integer not less than x

cos(x)

Calculate the cosine of x, with x in radians

cosd(x)

Calculate 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(x1,y1, x2,y2)

Calculates distance from x1,y1 to x2,y2

exp(x)

Calculates ex (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(x2+y2)

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.

logp1(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 radians.

tanh(x)

Calculates the hyperbolic tangent of x.

vangle(x1,y1, x2,y2)

Calculates the angle between the vector x1i + y1j and x2i + y2j . returns radians.

vangled(x1,y1, x2,y2)

Calculates the angle between the vector x1i + y1j and x2i + y2j . returns degrees.

2. CUBIT Functions

The following CUBIT Functions are available:

CUBIT Functions

Syntax

Description

get_error_count()

Gets the current error count in CUBIT

set_error_count(val) Sets the error count in CUBIT to value given
get_warning_count() Gets the current warning count in CUBIT

set_warning_count(val)

Sets the warning count in CUBIT to value given

Id("name")

Finds the Id of the entity with "name". Special case: use entity type ("body", "volume", "surface", "curve", "vertex" or "group") to get last created Id of that type.

IntNum(id)

Finds the number of intervals on curve with given id

IntSize(id)

Finds the interval size on curve with given id

Length(id)

Finds the length of the curve with given id

Radius(id)

Finds the radius of the curve at its midpoint with given id (useful only for arcs and circles)

Nx(id), Ny(id), Nz(id)

Finds the x, y or z-coordinate of node with given id

Vx(id), Vy(id), Vz(id) Finds the x, y or z-coordinate of vertex with given id

NumInGrp("groupname")

Finds the number of entities in the given group

3.String Functions

A few useful string functions are available:

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.

tostring(x)

Returns a string representation of the numerical varaible x. The variable x is unchanged.

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 {execute(svar)}

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 {rescan(svar)}

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.

error(svar) Outputs the string svar to stderr and then terminates the code with an error exit status

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 CUBIT 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}.