Declare a sec of statements/equations as a function

Syntax


function <ouput var> = <function name>(<arg1>, <arg2>, <arg3> …)

   <list of equations/statements>

end

Description


The FUNCTION keyword is used to declare a group of statements/equations to be treated as a mathematical function; that is, a mapping from zero or more input quantities to zero or one output quantity.  User-defined functions can be used similarly to built-in CSL functions (operators).  Currently, the list of input variables is shared with the rest of the model, so care must be taken to avoid name conflicts.  The return value of the function is equal to the value of the variable declared on the left side of the equal sign in the function declaration when the function exits.  Statements within a FUNCTION are not sorted.


In a limited sense, the FUNCTION statement replaces the MACRO capability of previous versions of CSL.  But which the MACRO capability had the effect of generating code at each place the MACRO was invoked, FUNCTION statements act more like their analogs in most modern programming languages.


Example


function ss = genlog(aa, kk, bb, mm, nn, cc, tt)

   dimension aa, kk, bb, mm, nn, cc, tt

   ss = aa + (kk - aa)/((cc + exp(-bb*(tt - mm)))^(1/nn))

end