function create

A function allows you to define a new function in terms of an Adams View expression. The function create command allows you to create a function. You may reverse this creation at a later time with an UNDO command.

Format:

 
function create
function_name =
new expr_function
text_of_expression =
string
argument_names =
string
type =
result_type
comments =
string
category =
func_category

Example:

As a simple example, we write a function which adds two numbers together
function create function_name=SUM argument_names=x,y &
text_of_expression="x + y"
Now we use this function to compute the sum of two numbers:
marker create marker=mar1 location=(SUM(1, 2)), 0, 0
If we examine the location of the marker mar1 we find that its location is 3,0,0 as expected.
Here we have a little more sophisticated example which computes the distance between two points:
function create function_name=DISTANCE argument_names=p1, p2 &
text_of_expression="sqrt((p1[1]-p2[1])**2 + (p1[2]-p2[2])**2 + (p1[3]-p2[3])**2)"
You could then use the distance function in any appropriate context (assuming the existence of a model containing par1 and par2).
variable create variable=dist1 real=(DISTANCE(par1.location, par2.location))

Description:

 
Parameter
Value Type
Description
function_name
New Expr_function
Specifies the name of the user-written function you are creating or modifying. You should choose a name which is meaningfully related to the operation that the function is performing.
text_of_expression
String
The TEXT_OF_EXPRESSION parameter defines the computation to be performed by the function.
argument_names
String
The ARGUMENT_NAMES parameter allows you to specify the names of the formal arguments in your function.
type
Array, Integer, Location_orientation, Object, Real, String
The TYPE parameter of a function indicates the type of the returned value.
comments
String
Allows you to add comments to the function for documentation purposes. The strings are stored in the database and written to command files.
category
User, String, Math, Modelling, Loc_ori, Matrix_array,database_object, Misc
Specifies which category this function should be classified under.

Extended Definition:

1. Remember that the value of the argument “text_of_expression” should be a character string, NOT an expression.
FUNCTION CREATE FUNCTION_NAME=SSQDIF &
ARGUMENT_NAMES=Array1, Array2 &
TEXT_OF_EXPRESSION="SSQ(Array1-Array2)" &
COMMENT_STRING="Compute sum of squares of differences between arguments" &
TYPE=real
2. The argument_names you specify are associated by position with the actual arguments when you invoke the function, using the following as an example:
FUNCTION CREATE FUNCTION_NAME=MyFunc ARGUMENT_NAMES=Arg1, Fred & TEXT_OF_EXPRESSION="sqrt(Fred) * Arg1"
VARIABLE CREATE VARIABLE_NAME=TestVariable &
REAL_VALUE=(MyFunc(1+1, 9) + 4)
The first formal argument "Arg1" is associated with the value 2 (computed from 1+1); the second argument, "Fred", is associated with the value 9. The resulting value for "TestVariable" is sqrt(9) * 2 + 4 = 10.