06.11.2013 Views

The Basis System - Weapons and Complex Integration - Lawrence ...

The Basis System - Weapons and Complex Integration - Lawrence ...

The Basis System - Weapons and Complex Integration - Lawrence ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

parameters in parentheses). <strong>The</strong> number of actual parameters must agree with the number of formal<br />

parameters (possibly zero) declared in the FUNCTION header.<br />

<strong>The</strong> second way to invoke a function is to use the CALL statement<br />

CALL name actualparams<br />

where name is the function being invoked. actualparams is optional; it can be absent if<br />

name was declared with no parameters, <strong>and</strong> present (with the same number of parameters) when<br />

name was declared with parameters. Whether or not name returns a value is irrelevant to the<br />

CALL statement, since the value is discarded. Presumably, CALL only makes sense if used with<br />

a function that has side effects, say giving values to global variables, displaying values, or running<br />

physics packages.<br />

If a function has no formal parameters then it can be called in any of the following ways:<br />

CALL name<br />

CALL name()<br />

name()<br />

name<br />

but of these only name() can be used in an expression, <strong>and</strong> only name or name() return a value.<br />

<strong>The</strong> meaning of a name is decided at execution time, so it is acceptable to define a function that<br />

calls a second function that has not yet been defined, as long as the second function is defined<br />

before the first function is executed. If this is not done, an error message will be received to the<br />

effect that the name does not exist. A function MAY call itself; logic to prevent infinite recursion<br />

is your responsibility.<br />

22.5 Examples of User Functions<br />

As an example of function definition, the following function computes the square root of its argument<br />

(if real <strong>and</strong> positive) within a specified tolerance:<br />

FUNCTION myroot (x,eps)<br />

REAL y= 1.,eps1 = max(abs(eps),1.e-12)<br />

IF (x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!