Next: 3 Dynamic arrays
Up: 2 Function interpreter
Prev: 2.1 Utilization
Index
Contents
This section illustrates, by means of an example, how to write a program calling a function interpreter.
The aim is to print the values of function f(x) for x = 0.0, 0.1, ..., 1.0.
PARAMETER (LM=1000) COMMON M(LM) 1000 FORMAT (' F(', F3.1, ') = ', F10.8) C C INITIALIZATION CALL INITIS(M, LM, 0, 0) CALL FONINI(M, 100, ICODE) C C READ THE DEFINITION OF F(X) WRITE (*,*) 'FUNCTION ?' CALL FONDES(M, IFON, ICODE) C C COMPUTE F(X) FOR X = 0.0, 0.1, ..., 1.0 WRITE (*,*) ' ' DO 100 I = 0, 10 X = REAL(I) / 10. CALL FON1RR(M, IFON, X, R, ICODE) WRITE (*,1000) X, R 100 CONTINUE END
FUNCTION ? F(X) = 2 * ASIN(X) ; F(0.0) = 0.00000000 F(0.1) = 0.20033485 F(0.2) = 0.40271586 F(0.3) = 0.60938531 F(0.4) = 0.82303369 F(0.5) = 1.04719758 F(0.6) = 1.28700233 F(0.7) = 1.55079496 F(0.8) = 1.85459054 F(0.9) = 2.23953891 F(1.0) = 3.14159274
As for all MODULEF programs, it is necessary to call utility
INITIS (p. ).
Next, utility FONINI initializes the function interpreter. It may be called several times, deleting thus the information saved before.
In order to analyze a user-defined function, utility FONDEF, as well as its variants FONDES and FONDEN, are used. A new function is memorized with each call, and the output parameter, IFON, restores this function in memory.
Different utilities execute a user-defined function: FON0RR, FON1RR, FON2RR, FON3RR (return a real value for 0, 1, 2 or 3 real arguments). Other utilities of this type can be developed.
Utility FONDRL returns the last line read in order, for example, to display it on screen.
Lastly, FONTER deletes the dynamic arrays required by the function interpreter.
This section contains the description, ordered alphabetically, of subprograms which are of interest to the programmer. For the most ample details, consult the commented source code.
A return code, ICODE, is returned by the most utilities. If no error was detected (normal execution) the value returned is 0. If not, a non-zero code is returned and an appropriate message is printed by utility FONERR.
The notation used for the utilities below |
is the usual notation (see Appendix A). |
SUBROUTINE FON0RR(,
,
,
)
INTEGER M(*), IFON, ICODE
REAL R
This utility executes a function with 0 real parameters and a real result.
SUBROUTINE FON1RR(,
,
,
,
)
INTEGER M(*), IFON, ICODE
REAL X, R
This utility executes a function with 1 real parameter and a real result.
SUBROUTINE FON2RR(,
,
,
,
,
)
INTEGER M(*), IFON, ICODE
REAL X, Y, R
This utility executes a function with 2 real parameters and a real result.
SUBROUTINE FON3RR(,
,
,
,
,
,
)
INTEGER M(*), IFON, ICODE
REAL X, Y, Z, R
This utility executes a function with 3 real parameters and a real result.
SUBROUTINE FONDEF(,
,
,
)
INTEGER M(*)
CHARACTER*(*) CFON
This utility analyses the function definition.
SUBROUTINE FONDEN(,
,
,
)
INTEGER M(*), MCOU(*)
This utility analyses the definitions of numbered functions:
<numbered function identifier> ::= <prefix> <number><prefix> ::= non-empty sequence of letters (A-Z) and underscores (_)
<number> ::= non-empty sequence of numbers
For example, the user can define two curves as follows:
COURBE3(X,Y) = X**2 + Y**2 - 1 ;COURBE5(X,Y) = (X-1.2)**2 + (Y-3.4)**nnnnnnn2 - 6.25 ;
FIN
The programmer initializes the elements of array MCOU to -1 and then calls utility FONDEN. On exit, only MCOU(3) and MCOU(5) are modified, referencing the user-defined functions.
SUBROUTINE FONDES(,
,
)
INTEGER M(*)
This utility analyses the definition of a function without returning its identifier.
SUBROUTINE FONDRL()
CHARACTER*(*) LIGNE
This utility returns the last line read.
SUBROUTINE FONINI(,
,
)
INTEGER M(*)
This utility initializes the function analyzer.
SUBROUTINE FONTER()
INTEGER M(*)
This utility frees space in memory once use of the function interpreter is terminated.