📄 fsubp.gml
字号:
.*
.np
.xt begin
The form of a
.kw RETURN
statement in a main program is:
.xt end
.mext begin
RETURN
.mext end
.np
.xt begin
When a
.kw RETURN
statement is executed in the main program, program execution
terminates in the same manner as the
.kw STOP
or
.kw END
statement.
This is an extension to FORTRAN 77.
.xt end
.*
.section RETURN Statement in Function Subprograms
.*
.np
The form of a
.kw RETURN
statement in a function subprogram is:
.mbox begin
RETURN
.mbox end
.np
When a
.kw RETURN
statement is executed in a function subprogram, the function value
must be defined.
Control is then passed back to the program unit that referenced it.
.*
.section RETURN Statement in Subroutine Subprograms
.*
.np
The form of a
.kw RETURN
statement in a subroutine subprogram is:
.mbox begin
RETURN [ e ]
.mbox end
.synote
.mnote e
is an integer expression.
.endnote
.pc
If the expression
.id e
is omitted or has a value less than one or greater than the number of
asterisks appearing in the dummy argument list of the subroutine or
entry name referenced, then control is returned to the next
executable statement that follows the
.kw CALL
statement in the referencing program unit.
If 1 <=
.id e
<=
.id n
where
.id n
is the number of asterisks appearing in the
.kw SUBROUTINE
or
.kw ENTRY
statement which contains the referenced name, then the expression
.id e
identifies the
.id e
.ct th
asterisk in the dummy argument list.
Control is returned to the statement identified by the alternate
return specified in the
.kw CALL
statement that corresponds to the
.id e
.ct th
asterisk in the dummy argument list of the referenced subroutine.
The following example demonstrates the use of alternate return
specifiers in conjunction with the
.kw RETURN
statement.
.cp 19
.exam begin
REAL X, Y
READ *, X, Y
CALL CMP( X, Y, *10, *20 )
PRINT *, 'X equals Y'
GOTO 30
10 PRINT *, 'X less than Y'
GOTO 30
20 PRINT *, 'X greater than Y'
30 END
SUBROUTINE CMP( X, Y, *, * )
IF( X .LT. Y )RETURN 1
IF( X .GT. Y )RETURN 2
RETURN
END
.exam end
.endlevel
.*
.section Subprogram Arguments
.*
.np
Arguments provide a means of communication between program units.
Arguments are passed to subprograms through argument lists and
are received by subprograms through argument lists.
.ix 'actual argument list'
.ix 'actual argument'
.ix argument actual
The argument list used to pass arguments to a subprogram is called the
.us actual argument list
and the arguments are called
.us actual arguments.
.ix 'dummy argument list'
.ix 'dummy argument'
.ix argument dummy
The argument list of the receiving subprogram is called the
.us dummy argument list
and the arguments are called
.us dummy arguments.
The actual argument list must agree with the dummy argument list in
number, order and type.
.beglevel
.*
.section Dummy Arguments
.*
.np
Statement function, external functions and subroutines use dummy
arguments to define the type of actual arguments they expect.
A dummy argument is one of the following.
.autopoint
.point
Variable.
.point
Array.
.point
Dummy procedure.
.point
Asterisk
.mono (*)
indicating a statement label.
.endpoint
.autonote Notes:
.setptnt 0 5
.note
A statement function dummy argument may only be a variable.
.note
An asterisk can only be a dummy argument for
a subroutine subprogram.
.endnote
.np
Dummy arguments that are variables of type INTEGER can be used in
dummy array declarators.
No dummy argument may appear in an
.kw EQUIVALENCE,
.kw DATA,
.kw PARAMETER,
.kw SAVE,
.kw INTRINSIC
or
.kw COMMON
statement except as a common block name.
A dummy argument must not be the same name as the subprogram name
specified in the
.kw FUNCTION,
.kw SUBROUTINE
or
.kw ENTRY
statement.
Other than these restrictions, dummy arguments can be used in the same
way an actual name of the same class would be used.
.*
.section Actual Arguments
.*
.np
Actual arguments specify the entities that are to be associated with
the dummy arguments when referencing a subroutine or function.
Actual arguments can be any of the following.
.autopoint
.point
Any expression, except 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.
.point
An external function or subroutine 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.
.endpoint
.autonote Notes:
.setptnt 0 5
.note
A statement function actual argument can only be a variable or an
expression.
.note
An alternate return specifier can only be an actual argument in the
actual argument list of a subroutine reference.
.endnote
.*
.section Association of Actual and Dummy Arguments
.*
.np
When a function or subroutine reference is executed, an association is
established between the actual arguments and the corresponding
dummy arguments.
The first dummy argument is associated with the first actual argument,
the second dummy argument is associated with the second actual argument,
etc.
Association requires that the types of the actual and dummy arguments
agree.
A subroutine has no type and when used as an actual argument
must be associated with a dummy procedure.
An alternate return specifier has no type and must be associated with
an asterisk.
Arguments can be passed through more than one level of procedure
reference.
In this case, valid association must exist at all intermediate levels
as well as the last level.
Argument association is terminated upon the execution of a
.kw RETURN
or
.kw END
statement.
.beglevel
.*
.section Length of Character Actual and Dummy Arguments
.*
.np
.ix 'dummy argument' 'of type CHARACTER'
If a dummy argument is of type CHARACTER, the corresponding actual
argument must also be of type CHARACTER and the length of the
dummy argument must be less than or equal to the length of the actual
argument.
If the length of the dummy argument is
.id len
then the
.id len
leftmost characters of the actual argument are associated with the
dummy argument.
.np
If a dummy argument of type CHARACTER is an array name, then the
restriction on the length is on the whole array and not for each
array element.
The length of an array element of the dummy argument may be different
from the length of the array element of the corresponding actual
array, array element, or array element substring, but the
dummy array argument must not extend beyond the end of the associated
actual array.
.*
.section Variables as Dummy Arguments
.*
.np
.ix 'dummy argument' variable
A dummy argument that is a variable may be associated with an actual
argument that is a variable, array element, substring or expression.
Only if the actual argument is a variable, array element or substring
can the corresponding actual argument be redefined.
.*
.section Arrays as Dummy Arguments
.*
.np
.ix 'dummy argument' array
A dummy argument that is an array may be associated with an actual
argument that is an array, array element or array element substring.
The number and size of the dimensions in the actual argument array
declarator may be different from the number and size of the dimensions
in the dummy argument array declarator.
.np
If the actual argument is a non-character array name, then the size of
the dummy argument array must not exceed the size of the actual argument
array.
An element of the actual array becomes associated with the
element in the dummy array with the same subscript value.
Association by array element of character arrays exists only if the
lengths of the array elements are the same.
If their lengths are not the same, the dummy and actual array elements
will not consist of the same characters.
.np
If the actual argument is a non-character array element name
whose subscript value is
.us asv
the size of the dummy argument array must not exceed the size of the
actual argument array less
.us asv - 1.
Furthermore, the dummy argument array element whose subscript value is
.us dsv
becomes associated with the actual argument array element whose
subscript value is
.us asv + dsv - 1.
Consider the following example.
.cp 14
.exam begin
DIMENSION A(10)
CALL SAM( A(3) )
END
SUBROUTINE SAM( B )
DIMENSION B(5)
.
.
.
END
.exam end
.pc
In the previous example, array
.id A
is an actual argument and the array
.id B
is the dummy argument.
Suppose we wanted to know which element of
.id A
is associated with the 4th element of
.id B.
Then
.us asv
would have value 3 since the array element
.id A(3)
is the actual argument, and
.us dsv
is 4.
Then the 4th element in
.id B
is 3 + 4 - 1 = 6th element of
A.
.np
If the actual argument is a character array name, character array
element name or character array element substring which begins at
character storage unit
.us ach,
then the character storage unit
.us dch
of the dummy argument array is associated with the character storage unit
.us ach + dch - 1
of the actual array.
The size of the dummy character array must not exceed the size of the
actual argument array.
.*
.section Procedures as Dummy Arguments
.*
.np
.ix 'dummy argument' 'dummy procedure'
A dummy argument that is a dummy procedure can only be associated
with an actual argument that is one of the following.
.autopoint
.point
Intrinsic function.
.point
External function.
.point
External Subroutine.
.point
Another dummy procedure.
.endpoint
.np
If the dummy argument is used as a subroutine (that is it is invoked
using a
.kw CALL
statement) then the corresponding actual argument must either be
a subroutine or a dummy procedure.
If the dummy argument is used as an external function, then the
corresponding actual argument must be an intrinsic function, external
function or dummy procedure.
Note that it may not be possible to determine in a given program unit
whether a dummy procedure is associated with a function or subroutine.
In the following example
it is not possible to tell by looking at this program unit whether
.id PROC
is an external subroutine or function.
.cp 13
.exam begin
SUBROUTINE SAM( PROC )
EXTERNAL PROC
.
.
CALL SAM1( PROC )
.
.
.
END
.exam end
.*
.section Asterisks as Dummy Arguments
.*
.np
.ix 'dummy argument' asterisk
A dummy argument that is an asterisk may only appear in the dummy
argument list of a
.kw SUBROUTINE
statement or an
.kw ENTRY
statement in a subroutine subprogram and may be associated only with
an actual argument that is an alternate return specifier in a
.kw CALL
statement which references the subroutine.
.cp 15
.exam begin
CHARACTER*10 RECORD(5)
I = 2
CALL SAM( I, *999, 3HSAM )
PRINT *, 'I should be skipped'
999 PRINT *, 'I should be printed'
END
SUBROUTINE SAM( I, *, K)
CHARACTER*3 K
PRINT *, K
RETURN 1
END
.exam end
.endlevel
.endlevel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -