📄 fsubp.gml
字号:
.*
.np
When an external function is referenced in an expression
.xt on
or a
.kw CALL
statement,
.xt off
the following steps are performed.
.autopoint
.point
The actual arguments are evaluated.
.point
The actual arguments are associated with the corresponding dummy
arguments.
.point
The external function is executed.
.endpoint
.np
The type of the external function reference must be the same as the
type of the function name in the external function subprogram.
If the external function is of type CHARACTER, the length must also
match.
.*
.section Actual Arguments for an External Function
.*
.np
An actual argument must be one of the following.
.autopoint
.point
Any expression except a character expression involving the
concatenation of an operand whose length specification is
.mono (*)
unless the operand is a symbolic constant.
.point
An array name.
.point
An intrinsic function name (must be the specific name) that has appeared
in an
.kw INTRINSIC
statement.
.point
An external procedure name.
.point
A dummy procedure name.
.endpoint
.np
The actual arguments of an external function reference must match
the order, number and type of the corresponding dummy arguments.
If a subroutine is an actual argument, then type agreement is not
required since a subroutine has no type.
.*
.section External Function Subprogram Restrictions
.*
.autonote
.setptnt 0 5
.note
The name of an external function is a global name and must not be
the same as any other global name or name local to the subprogram
whose name is that of the external function.
Note that the external function name is treated as a variable within the
external function subprogram.
.note
The name of a dummy argument is a name local to the subprogram and must
not appear in an
.kw EQUIVALENCE,
.kw PARAMETER,
.kw SAVE,
.kw INTRINSIC
or
.kw DATA
statement within the same subprogram.
It may appear in a
.kw COMMON
statement only as the name of a common block.
.note
The name of the external function can in no way, directly or indirectly,
be referenced as a subprogram from within the subprogram it defines.
It can appear in a type statement to establish its type only if
the type has not been established in the
.kw FUNCTION
statement.
.endnote
.endlevel
.*
.section Subroutines
.*
.np
.ix subroutine
A
.us subroutine
is a program unit that has a
.kw SUBROUTINE
statement as it first statement.
It is defined externally to the program units that reference it.
The form of a
.kw SUBROUTINE
statement can be found in the chapter entitled :HDREF refid='fstats'..
.np
A subroutine differs from a function in that it does not return
a result and hence has no type associated with it.
However, it is possible to return values from a subroutine by
defining or redefining the dummy arguments of the subroutine.
.beglevel
.*
.section Referencing a Subroutine: The CALL Statement
.*
.np
Unlike a function, a subroutine cannot appear in an expression.
Subroutines are referenced by using a
.kw CALL
statement.
See the chapter entitled :HDREF refid='fstats'. for details on the
.kw CALL
statement.
When a
.kw CALL
statement is executed, the following steps are performed.
.autopoint
.point
The actual arguments are evaluated.
.point
The actual arguments are associated with the corresponding dummy
arguments.
.point
The subroutine is executed.
.endpoint
.np
A subroutine can be called from any subprogram but must not be
called by itself, indirectly or directly.
.*
.section Actual Arguments for a Subroutine
.*
.np
Each actual argument in a subroutine call must be one of the following.
.autopoint
.point
Any expression except a character expression involving the
concatenation of an operand whose length specification is
.mono (*)
unless the operand is a symbolic constant.
.point
An array name.
.point
An intrinsic function name (must be the specific name) that has appeared
in an
.kw INTRINSIC
statement.
.point
An external procedure name.
.point
A dummy procedure name.
.point
.ix 'alternate return specifier'
An
.us alternate return specifier
of the form
.id *s
where
.id s
is a statement number of an executable statement in the subprogram
which contained the
.kw CALL
statement.
This will be covered in more detail when the
.kw RETURN
statement is discussed.
.endpoint
.np
The actual arguments must agree in order, number and type with the
corresponding dummy arguments.
The type agreement does not apply to an actual argument which
is an alternate return specifier or a subroutine name since
neither has a type.
.*
.section Subroutine Subprogram Restrictions
.*
.autonote
.setptnt 0 5
.note
A subroutine subprogram can contain any statement except a
.kw FUNCTION,
.kw BLOCK DATA
or
.kw PROGRAM
statement.
.note
The name of a subroutine is a global name and must not be used as
another global name.
Furthermore, no local name in the subroutine subprogram can have the
same name as the subroutine.
.note
The name of a dummy argument is local to the subroutine subprogram
and must not appear in an
.kw EQUIVALENCE,
.kw PARAMETER,
.kw SAVE,
.kw INTRINSIC
or
.kw DATA
statement.
It may appear in a
.kw COMMON
statement only as the name of a common block.
.endnote
.endlevel
.*
.section The ENTRY Statement
.*
.np
An
.kw ENTRY
statement allows execution of a subprogram to begin at a particular
executable statement within the subprogram in which it appears.
.ix 'entry point'
An
.kw ENTRY
statement defines an alternate
.us entry point
into a subprogram
and can appear anywhere after the
.kw FUNCTION
statement in a function subprogram or the
.kw SUBROUTINE
statement in a subroutine subprogram.
Also, it must not appear as a statement between the beginning and end
of a control structure.
For example, an
.kw ENTRY
statement cannot appear between a block
.kw IF
statement and its corresponding
.kw END IF
statement or between a
.kw DO
statement and the corresponding terminal statement.
It is possible to have more than one
.kw ENTRY
statement in a subprogram.
An
.kw ENTRY
statement is a non-executable statement.
The form of an
.kw ENTRY
statement can be found in the chapter entitled :HDREF refid='fstats'..
.np
Each entry name defines an external function if it appears in a
function, or an external subroutine if it appears in a subroutine
and is referenced in the same way as the actual function or subroutine
name would be referenced.
Execution begins at the first executable statement that follows
the
.kw ENTRY
statement.
The order, number, type and names of the dummy argument lists
of an
.kw ENTRY
statement may be different from that of a
.kw FUNCTION,
.kw SUBROUTINE
or other
.kw ENTRY
statement.
However, there must still be agreement between the actual argument list
used to reference an entry name and the dummy argument list in the
corresponding
.kw ENTRY
statement.
.beglevel
.*
.section ENTRY Statements in External Functions
.*
.np
Entry names may also appear in type statements.
Their type may or may not be the same type as other entry names or
the actual name of the external function unless the function is of type
CHARACTER.
If the function is of type CHARACTER then the type of all the entry
names must be of type CHARACTER.
Conversely, if an entry name is of type CHARACTER, then all other entry
names and the function name must be of type CHARACTER.
An entry name, like external function names, is treated as a variable
within the subprogram it appears.
Within a function subprogram, there is an association between variables
whose name is an entry name and the variable whose name corresponds to
the external function.
When such a variable becomes defined, all other such variables of the
.us same
type also become defined and other such variables not of the
same type become undefined.
This can be best illustrated by an example.
.cp 19
.exam begin
PRINT *, EVAL(2), EVAL3(4.0)
END
INTEGER FUNCTION EVAL( X )
INTEGER EVAL2, X
REAL EVAL3, Y
C = 1
GOTO 10
ENTRY EVAL2( X )
C = 2
GOTO 10
ENTRY EVAL3( Y )
C = 3
10 EVAL2 = C * X
END
.exam end
.pc
In the previous example, invoking
.id EVAL
would cause the result of
2 to be returned even though
.id EVAL
was never assigned to in the function
.id EVAL;
but since
.id EVAL2
and
.id EVAL
are of the same type they are
associated and hence defining
.id EVAL2
causes
.id EVAL
to be defined.
However, invoking
.id EVAL3
would cause an undefined result to be
returned since
.id EVAL3
is of type REAL and
.id EVAL2
is of type INTEGER and
hence are not associated.
.id EVAL3
does not become defined.
.*
.section ENTRY Statement Restrictions
.*
.autonote
.setptnt 0 5
.note
An entry name may not appear in any statement previous to the
.kw ENTRY
statement containing the entry name except in a type statement.
.note
If an entry name in a function is of type CHARACTER, each entry name
and the name of the function must also be of type CHARACTER.
If the name of the function or the name of any entry point has a
length specification of
.mono (*),
then all such entities must have a length specification of
.mono (*);
otherwise they must all have a length specification
of the same integer value.
.note
If a dummy argument appears in an executable statement, then that
statement can be executed provided that the dummy argument is in the
dummy argument list of the procedure name referenced.
.note
A name that appears as a dummy argument in an
.kw ENTRY
statement must not appear in the expression of a statement function
unless it is a dummy argument of the statement function, it has
appeared in the dummy argument list of a
.kw FUNCTION
or
.kw SUBROUTINE
statement, or the
.kw ENTRY
statement appears before the statement function statement.
.note
A name that appears as a dummy argument in an
.kw ENTRY
statement must not appear in an executable statement preceding
the
.kw ENTRY
statement unless it has also appeared in a
.kw FUNCTION,
.kw SUBROUTINE,
or
.kw ENTRY
statement that precedes the executable statement.
.endnote
.endlevel
.*
.section The RETURN Statement
.*
.np
A
.kw RETURN
statement is a way to terminate the execution of a function or
subroutine subprogram and return control to the program unit that
referenced it.
.xt on
As an extension to FORTRAN 77, &product permits the use of the
.kw RETURN
statement in the main program.
.xt off
A subprogram (or main program) may contain more than one
.kw RETURN
statement or it may contain no
.kw RETURN
statement.
In the latter case, the
.kw END
statement has the same effect as a
.kw RETURN
statement.
.np
Execution of a
.kw RETURN
or
.kw END
statement causes all local entities to become undefined except for the
following.
.autopoint
.point
Entities specified in a
.kw SAVE
statement.
.point
Entities in blank common.
.point
Initially defined entities that have neither been redefined nor become
undefined.
.point
Entities in a named common block that appears in the subprogram
and in a program unit that references the subprogram directly or
indirectly.
.endpoint
.*
.beglevel
.*
.section RETURN Statement in the Main Program (Extension)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -