Intel fortran-80 manual Chapter Functions And Subroutines, 5.1Intrinsic and Statement Functions

Models: fortran-80

1 130
Download 130 pages 742 b
Page 49
Image 49
CHAPTER 5

CHAPTER 5

FUNCTIONS AND SUBROUTINES

Functions and subroutines reduce coding, break programs into readily-visible logical structures, conserve storage, avoid the tedium and increased probability of error in repetitive coding, and eliminate the coding of commonly-used mathematical functions.

The term 'function' refers to a statement or subprogram that returns a value when it is referenced. A subroutine is a subprogram that does not return a value, but may alter the values of variables outside itself.

All functions and subroutines are called 'procedures.' These include:

Intrinsic, or predefined, FORTRAN functions;

Single-statement, user-defined functions (statement functions);

User-defined function subprograms (external functions), which are identified by their initial FUNCTION statement;

Subroutine subprograms identified by their initial SUBROUTINE statement.

External functions and subroutines are referred to collectively as 'external pro- cedures.' These may be FUNCTION or SUBROUTINE subprograms defined within the program, or they may be procedures created elsewhere (e.g., PL/M and assembly language procedures) and linked to the program where appropriate.

When a procedure is defined, it usually includes 'dummy arguments' used to hold the place of 'actual arguments' to be substituted when the procedure is referenced or called. The use of dummy and actual arguments will become clearer in the remainder of this chapter.

5.1Intrinsic and Statement Functions

5.1.1Intrinsic Functions

FORTRAN provides a number of predefined functions for performing common operations such as square root calculation, type conversion, trigonometric calcula- tions, etc. The complete list of available intrinsic functions can be found in Appen- dix B. This appendix shows the names of the various intrinsic functions, their func- tion definitions, type of arguments, and type of results. For those intrinsic functions that have more than one argument, all arguments must be of the same type. The IM- PLICIT statement has no effect on the types of intrinsic functions.

An intrinsic function is referenced by specifying it in an expression.

A = 33 + SQRT(8)

The resulting value depends on the value of the actual argument(s) used in the reference (for example, the actual value of 'B' in the expression above). The actual arguments that constitute the argument list must agree in type, number, and order with the specifications in Appendix B and may be any expression of the specified type.

Arguments for which the result is not mathematically defined or which exceed the numerical range of the processor cause results not defined in this manual. Restric- tions on the range of arguments and results for intrinsic functions are listed in the notes in Appendix B.

5-1

Page 49
Image 49
Intel fortran-80 manual Chapter Functions And Subroutines, 5.1Intrinsic and Statement Functions, 5.1.1Intrinsic Functions