• Keine Ergebnisse gefunden

DUMMY PROCEDURES

Im Dokument COMPUTER SYSTEMS (Seite 90-94)

2. PROGRAM STRUCTURE

2.2 PROGRAM UNITS

2.5.4 DUMMY PROCEDURES

A dummy procedure is a dummy argument used as a procedure name in a

call to an external procedure. This allows a procedure call to specify a second procedure to be referenced by the called procedure. In the

following example, dummy argument S is associated with subroutine SUBB, which causes the CALL statement to call subroutine SUBB with argument A.

FUNCTION HIGHEST(S,Z) TOP=HIGHEST(SUBB,A)

CALL S(Z) END

Before being passed as actual arguments, procedure names are declared in EXTERNAL or INTRINSIC statements, to distinguish them from other kinds of arguments. Statement functions cannot be used as dummy procedures. The use of the EXTERNAL statement allows replacing an intrinsic function with another function that is better suited to a given application; when this is done, the intrinsic function of the same name is unavailable.

A dummy procedure name must be associated with an actual argument that is a procedure; the procedure must be available at the time a reference to it is executed. If a dummy argument is referenced as a subroutine, the actual argument must be the name of a subroutine and must not appear in a type statement or be referenced as a function. If a dummy argument

appears in a type statement and an EXTERNAL statement, the actual argument must be the name of a function.

When an intrinsic function name is passed to a procedure to be used in a function reference within the procedure, the arguments in the function reference must agree in number and type with those specified for the intrinsic function. As with dummy arguments, the type of a dummy

procedure must match the type of its actual argument when it is used as a function. (See the intrinsic functions in appendix B.)

A dummy procedure name must appear in the dummy argument list of a FUNCTION, SUBROUTINE, or ENTRY statement. It cannot be the name of an array or character variable and is immediately followed by a left parenthesis except: as an arg~ent; in a type, EXTERNAL, or CALL

statement; or as a common block name in a COMMON or SAVE statement. A dummy function subprogram name must be declared in an EXTERNAL or INTRINSIC statement.

2.5.4.1 EXTERNAL statement

An EXTERNAL statement identifies a symbolic name as representing an external procedure and permits its use as an actual argument.

Format:

EXTERNAL proc [,proc] .•.

proc Name of an external procedure, dummy procedure, or block data subprogram

The appearance of a name in an EXTERNAL statement declares that name to be an external procedure name. If an external procedure name is to be an actual argument in a program unit, it must appear in an EXTERNAL

statement in that program unit. A statement function name must not appear in an EXTERNAL statement.

If an intrinsic function or utility procedure name appears in an EXTERNAL statement, that name becomes the name of some external procedure. The intrinsic function or utility procedure of the same name is not available for reference in that program unit.

A given symbolic name can appear only once in all of the EXTERNAL statements of a program unit.

2.5.4.2 INTRINSIC statement

An INTRINSIC statement identifies a symbolic name as an intrinsic function. It permits use of a specific intrinsic function name as an actual argument.

Format:

INTRINSIC fun[,fun] ..•

fun Intrinsic function name

The appearance of a name in an INTRINSIC statement declares that name to be an intrinsic function name. If an intrinsic function name is an actual argument in a program unit, it must appear in an INTRINSIC statement in that program unit.

The following intrinsic function names must not appear as actual arguments.

AMAXO CHAR DMINl IFIX LLE MAX 1 REAL

AMAXl CMPLX FLOAT INT LLT MIN SNGL

AMINO DBLE ICHAR LGE MAX MINO

AMINl DMAXl IDINT LGT MAXO MINl

The appearance of a generic function name in an INTRINSIC statement does not cause loss of the name's generic property.

A given symbolic name must not appear in both an EXTERNAL and an

INTRINSIC statement. In addition, it can appear only once in all of the INTRINSIC statements of a program unit. Appendix B lists the intrinsic functions.

3 • DATA TYPES

Data can be speci~ied or input in a FORTRAN ~rogram as a constant, a variable, an array, an array element, or a function reference. A constant is an invariant value, which cannot be modified. A variable is a name that can assume different values during program execution. An array is an ordered set of data items of the same type identified by a single name. An array ~lement is one item ~n an array and, like a variable, can assume different values during Progr~ execution; it is identified by the array name and one or more numbers to specify its position within the array. Functions are discussed in section 2; the other terms above are disc~ssed in section 4.

Each data item has a data type, which specifies how the item is represented, stored, and manipulated. Pata types can be any of t~e

following.

• Integer - integral, signed values

~eal - values approximating real numbers, consisting of a mantissa and an e~ponent

• Double-precision - the s~e as real data, but extended to about twice the precision

• Complex - val~es approximating co~plex numbers as pairs of signed, real data items. The first item in the ~air represents the real portion and the second, the imaginary por~ion of the data.

• Logical - the log~ca~ values true and false

• Caaracter - se9uences of characters

• Pointer - values representing storage addresses; only a variable can have a pointer value.

• Boolean - octal values representing the binary contents of Cray words; only constants, intrinsic functions, or expressions can be Boolean.

An arithmetic value is a number that can be used in an arithmetic

operation, and can be of type integer, rea~, double-precision, complex.

Table 3~1 shows some examFles of values represented in these data types.

Pointer variables, Boolean constants, and Hol+erith constants can also be used in limited ways i~ arithmetic expressions.

The ANSI FORTRAN Standard does not provide for the Boolean or pointer data types.

After a symbolic name is identified with a type, that type applies to all uses of that name. Exception: a common block can have the same name as a variable or array, but the common block name has no type.

A data type (for a symbolic constant, variable, array, external function or statement function) can be specified explicitly in a type statement or implicitly by the first letter of its symbolic name. If no type is

specified, a first letter of I, J, K, L, M, or N implies type integer;

any other first letter implies type real. The default for implied typing can be changed or confirmed by an IMPLICIT statement. Type statements and the IMPLICIT statement are discussed in subsections 3.1.1 and 3.1.2.

The data type of an array element is the same as the data type of the array that contains it.

The data type of a function establishes the type of data returned when the function is referenced in an expression. The data type of a user-specified function can be implied by its name, user-specified in a type statement, or specified within a function subprogram. The names of intrinsic functions can be specific or generic, so that the result type agrees with the type of the data passed to the function. See section 2 and appendix B.

Im Dokument COMPUTER SYSTEMS (Seite 90-94)