📄 fstruct.gml
字号:
- control will pass to the statement after the
.kw END SELECT
statement
.point (vi)
.id I = 5, 6, ...:
.br
- control will pass to the statement after the
.kw END SELECT
statement
.endpoint
.np
.kw CASE DEFAULT
allows a block of code to be specified for execution when the
.kw SELECT
expression is out of range.
It must follow all CASE-blocks and thus is ended by the
.kw END SELECT
statement.
The
.kw CASE DEFAULT
statement terminates the previous and last CASE-block.
Note that only one
.kw CASE DEFAULT
block may be specified in a SELECT construct.
.np
If a
.kw CASE DEFAULT
block were included in the above example, it would be executed in
cases (i) and (vi) of the description.
After a
.kw CASE DEFAULT
block is executed, control then passes to the statement after the
.kw END SELECT
statement.
.np
Empty or null case blocks are permitted (that is, two
.kw CASE
statements with no statements between).
The net result of executing a null CASE-block is to effectively bypass
the SELECT construct.
.keep 20
.exam begin
SELECT CASE ( I * 4 - J )
CASE (-10 : -5)
PRINT *,'First case:'
PRINT *,'-10 <= I*4-J <= -5'
CASE (-4 : 2)
PRINT *,'Second case:'
PRINT *,'-4 <= I*4-J <= 2'
CASE (3, 5, 7)
PRINT *,'Third case:'
PRINT *,'I*4-J is one of 3, 5 or 7'
CASE (4, 6, 8:10)
PRINT *,'Fourth case:'
PRINT *,'I*4-J is one of 4, 6, 8, 9 or 10'
CASE DEFAULT
PRINT *,'All other cases:'
PRINT *,'I*4-J < -10 or I*4-J > 10'
END SELECT
.exam end
.pc
This example will execute in the manner described below for each
of the possible values of expression
.mono I*4-J.
.begpoint
.point (i)
expression < &minus.10
.br
- control will pass to the statement after the
.kw CASE DEFAULT
statement
.br
- the string
.mono All other cases:
will be printed
.br
- the string
.mono I*4-J < -10 or I*4-J > 10
will be printed
.point (ii)
&minus.10 <= expression <= &minus.5:
.br
- control will pass to the statement after the first
.kw CASE
statement
.br
- the string
.mono First case:
will be printed
.br
- the string
.mono -10 <= I*J-4 <= -5
will be printed
.br
- control will pass to the statement after the
.kw END SELECT
statement
.point (iii)
&minus.4 <= expression <= 2:
.br
- control will pass to the statement after the second
.kw CASE
statement
.br
- the string
.mono Second case:
will be printed
.br
- the string
.mono -4 <= I*J-4 <= 2
will be printed
.br
- control will pass to the statement after the
.kw END SELECT
statement
.point (iv)
expression = 3, 5 or 7:
.br
- control will pass to the statement after the third
.kw CASE
statement
.br
- the string
.mono Third case:
will be printed
.br
- the string
.mono I*J-4 is one of 3, 5 or 7
will be printed
.br
- control will pass to the statement after the
.kw END SELECT
statement
.point (v)
expression = 4, 6, 8, 9 or 10:
.br
- control will pass to the statement after the fourth
.kw CASE
statement
.br
- the string
.mono Fourth case:
will be printed
.br
- the string
.mono I*J-4 is one of 4, 6, 8, 9 or 10
will be printed.
.br
- control will pass to the statement after the
.kw END SELECT
statement
.point (vi)
expression > 10:
.br
- control will pass to the statement after the
.kw CASE DEFAULT
statement
.br
- the string
.mono All other cases:
will be printed
.br
- the string
.mono I*4-J < -10 or I*4-J > 10
will be printed
.endpoint
.*
.keep 10
.section EXECUTE and REMOTE BLOCK
.*
.mext begin
EXECUTE name
.
.
.
REMOTE BLOCK name
statement(s)
END BLOCK
.mext end
.synote 5
.mnote name
is a valid FORTRAN symbolic name.
.endnote
.np
The
.kw EXECUTE
statement, an extension to FORTRAN 77, allows a named block of code to
be executed.
The named block of code may be defined anywhere in the same program
unit and is delimited by the
.kw REMOTE BLOCK
and
.kw END BLOCK
statements.
Executing a REMOTE-block is similar in concept to calling a
subroutine, with the advantage that shared variables do not need to be
placed in a common block or passed in an argument list.
In addition there is less overhead involved in executing a
REMOTE-block than in calling a subroutine (in both amount of object
code and execution time).
When execution of the REMOTE-block is complete, control returns to the
statement following the
.kw EXECUTE
statement which invoked it.
.np
This feature is helpful in avoiding duplication of code for a function
(such as I/O) required in a number of places throughout a program.
It can also be an aid to writing a well-structured program.
.np
Each REMOTE-block within the same program unit must have a different
name and it must not be a subprogram or variable name.
Note that a REMOTE-block is local to the program unit in which it is
defined and may not be referenced (executed) from another program
unit.
.np
REMOTE-blocks may be defined anywhere in the program unit except as
follows.
.autopoint
.point
They must follow all specification statements.
.point
They must not be defined within a control structure.
.endpoint
.np
If a
.kw REMOTE BLOCK
statement is encountered during execution, control is transferred to
the statement following the corresponding
.kw END BLOCK
statement.
.sk 1 c
Note that the nested definition of REMOTE-blocks is not permitted.
.keep 20
.exam begin
EXECUTE A
PRINT *, 'FIRST'
.
.
.
EXECUTE A
PRINT *, 'SECOND'
.
.
.
REMOTE BLOCK A
I = I + 1
PRINT *, 'I=', I
END BLOCK
.exam end
.np
Both
.kw EXECUTE
statements will cause REMOTE-block
.id A
to be executed.
That is, variable
.id I
will be incremented and its value will be printed.
When the block has been executed by the first
.kw EXECUTE
statement, control returns to the
.kw PRINT
statement following it and the word
.mono FIRST
is printed.
Similarly, when the block is executed by the second
.kw EXECUTE
statement, control returns to the
.kw PRINT
statement following it and the word
.mono SECOND
is printed.
.np
REMOTE-blocks may be executed from other REMOTE-blocks.
For example, REMOTE-block
.id A
might contain the statement
.mono EXECUTE B,
where
.id B
is a REMOTE-block defined elsewhere in the program unit.
The execution of REMOTE-blocks from other REMOTE-blocks may take place
to any level; however, the recursive execution of REMOTE-blocks is not
permitted, either directly or through a chain of
.kw EXECUTE
statements.
Attempts to execute REMOTE-blocks recursively are detected as errors
at execution time.
.*
.keep 18
.section GUESS-ADMIT-END GUESS
.*
.mext begin
GUESS [: block-label]
statement(s)
ADMIT
statement(s)
ADMIT
statement(s)
.
.
.
ADMIT
statement(s)
END GUESS
.mext end
.np
The GUESS-ADMIT-END GUESS structure is a rejection mechanism which is
useful when sets of statements are to be conditionally chosen for
execution, but not all of the conditions required to make a selection
are available beforehand.
It is an extension to FORTRAN 77.
The sets of statements to be chosen may be thought of as alternatives,
the first alternative being statements immediately after the
.kw GUESS
statement.
Execution begins with the statements in the first alternative.
If a condition is detected which indicates that the first alternative
was the wrong choice, a
.kw QUIT
statement may be executed to cause control to be passed to the
statements after the
.kw ADMIT
statement (i.e., the second alternative).
A
.kw QUIT
statement within the second alternative passes control to the third
alternative, etc.
A
.kw QUIT
statement within the last alternative passes control to the statement
after the
.kw END GUESS
statement.
If an alternative completes execution without encountering a
.kw QUIT
statement (i.e., all statements are executed up to the next
.kw ADMIT
statement) then control is passed to the statement after the
.kw END GUESS
statement.
An optional block label may be specified following the keyword
.kw GUESS
(see the
.kw QUIT
statement for more information).
.np
In the following example, two sets of codes and numbers are read in
and some simple sequence checking is performed.
If a sequence error is detected an error message is printed and
processing terminates; otherwise the numbers are processed and another
pair of numbers is read.
.keep 20
.exam begin
LOOP : PRLOOP
GUESS
LINE = LINE + 1
READ *, ICODE, X
AT END, QUIT :PRLOOP
IF( ICODE .NE. 1 )QUIT
LINE = LINE + 1
READ *, ICODE, Y
AT END, QUIT
IF( ICODE .NE. 2 )QUIT
PRINT *, X, Y
CALL PROCES(X, Y)
ADMIT
PRINT *, 'INVALID SEQUENCE: LINE =', LINE
QUIT :PRLOOP
END GUESS
END LOOP
.exam end
.np
The above example attempts to read a code and number.
If an end of file occurs then the loop is terminated by the
.kw QUIT
statement.
.np
If the code is not 1 then we did not get what we expected and an
error situation has arisen.
Control is passed to the statement following the
.kw ADMIT
statement.
An error message is printed and the loop is terminated by the
.kw QUIT
statement.
.np
If the code is 1 then a second code and number are read.
If an end of file occurs then we are missing a set of data and an
error situation has arisen.
Control is passed to the statement following the
.kw ADMIT
statement.
An error message is printed and the loop is terminated by the
.kw QUIT
statement.
Similarly if the expected code is not 2 an error situation has arisen.
Control is passed to the statement following the
.kw ADMIT
statement.
An error message is printed and the loop is terminated by the
.kw QUIT
statement.
.np
If the second code is 2, the values of variables
.id X
and
.id Y
are printed.
A subroutine is then called to process the data.
Control resumes at the statement following the
.kw END GUESS
statement.
Since this statement is an
.kw END LOOP,
control is transferred to the beginning of the loop.
.np
The above example illustrates the point that all the information
required to make a choice (in this case between a valid set of data
and an invalid set) is not available from the beginning.
In this case we make an assumption that the data values are correct
(our hypothesis) and then test the assumption at various points in the
algorithm.
If any of the tests fail we reject the hypothesis (and, perhaps,
select a new hypothesis).
.np
It should be noted that no alternative selection need be coded (i.e.,
we need not use any ADMIT-blocks).
This is illustrated in the following example.
.keep 10
.exam begin
GUESS
X=SQRT( X )
IF( X .LT. EPS )QUIT
X=Y+SQRT(Y)
IF( X .LT. EPS )QUIT
CALL INTGRT( X, Y )
END GUESS
.exam end
.np
It might be noted that the IF-ELSE-END IF construct is simply
a specific instance of the more general GUESS-ADMIT-END GUESS
construct wherein the data values are known beforehand (as could be
illustrated using the previous example).
.*
.keep 10
.section QUIT
.*
.mext begin
QUIT [ : block-label]
.mext end
.np
The
.kw QUIT
statement may be used to transfer control to the first executable
statement following the terminal statement of the block in which it is
contained.
.np
When transferring out of a loop, control is passed to the statement
following the
.kw END DO,
.kw END WHILE,
.kw END LOOP
or
.kw UNTIL
statement.
.np
When transferring out of a GUESS block, control is passed to the
statement after the next
.kw ADMIT
or
.kw END GUESS
statement.
.np
When transferring out of an IF-block or SELECT-block,
control is passed to the statement after the corresponding
.kw END IF
or
.kw END SELECT
statement.
.np
When transferring out of a REMOTE-block, control passes to the
statement following the
.kw EXECUTE
statement that invoked the REMOTE-block.
.np
If no block label is specified in the
.kw QUIT
statement, control is transferred from the immediately enclosing
structure.
If several structures or DO-loops are nested, it is possible to exit
from any one of them by specifying the block label of the
corresponding block structure.
.np
The
.kw QUIT
statement is most commonly used as the statement in a logical
.kw IF
or
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -