📄 farrays.gml
字号:
.ix 'constant array declarator'
.ix 'array declarator' 'constant'
is one in which each of the dimension bound expressions is an integer
constant expression.
It is called a constant array declarator because the dimension bound
expressions can never change.
In the following example both
.id A(10)
and
.id B(&minus.5:5)
are constant array declarators.
.exam begin
SUBROUTINE SQUARE( A )
DIMENSION A(10), B(-5:5)
.
.
.
END
.exam end
.*
.section Adjustable Array Declarator
.*
.np
An
.us adjustable array declarator
.ix 'adjustable array declarator'
.ix 'array declarator' 'adjustable'
is one that contains at least one variable in all of its dimension
bound expressions.
It is called an adjustable array declarator because the dimension bound
expressions can change depending on the current value of the variables
in the dimension bound expressions.
The array name must be a dummy argument.
In the following example,
.id A(M,2*N)
is an adjustable array declarator.
If
.id SQUARE
is called with
.id M
having value 5 and
.id N
having value 10, then
the array
.id A
will be a 2-dimensional array having 5 rows and 20 columns.
.exam begin
SUBROUTINE SQUARE( A, M, N )
DIMENSION A(M,2*N)
.
.
.
END
.exam end
.*
.section Assumed-size Array Declarator
.*
.np
An
.us assumed-size array declarator
.ix 'assumed-size array declarator'
.ix 'array declarator' 'assumed-size'
is a constant array declarator or an adjustable array declarator whose
upper dimension bound of the last dimension is an asterisk
(e.g., A(M,N,*))
.xt on
or the integer value 1
(e.g., A(M,N,1)).
.xt off
The array name must be a dummy argument.
The value of the upper bound of the last dimension is
determined by the number of elements of the actual array argument and
is computed as follows.
First we compute the size of the dummy array.
Note that this size is really an upper bound.
.autonote
.note
If the corresponding actual array argument is a non-character array
name, the size of the dummy array is the size of the actual array.
.note
If the corresponding actual array argument is a non-character array
element name with a subscript value of
.us r
in an array of size
.us x,
the size of the dummy array is
.us x
+ 1 &minus.
.us r.
.note
If the corresponding actual argument is a character array name,
character array element or a substrung character array element which
begins at character
.us t
of an array with
.us c
characters then the size of the dummy array is INT((
.us c
+ 1 &minus.
.us t
) /
.us e)
where
.us
e
is the size of an element of the dummy array.
.endnote
.np
If the assumed-size array has dimension
.us
n
then the product of the first
.us
n
&minus. 1 dimensions must be less than or equal to the size of the array
as determined by one of the preceding rules.
The value of the assumed dimension is the largest integer
such that the product of all of
the dimensions is less than or equal to the size of the dummy array.
In the following example,
.id A(4,*)
is an assumed-size array declarator.
.exam begin
DIMENSION B(10)
.
.
.
CALL SQUARE( B )
.
.
.
END
SUBROUTINE SQUARE( A )
DIMENSION A(4,*)
.
.
.
END
.exam end
.pc
By rule 1, the upper bound of the size of
.id A
is 10.
We now look for the largest integer
.us
n
such that 4 *
.us
n
is less than or equal to 10.
Clearly,
.us
n
is 2.
.id A
is therefore a 2-dimensional array with 4 rows and 2 columns.
.*
.section Allocatable Array Declarator
.*
.np
An
.us allocatable array declarator
.ix 'allocatable array declarator'
.ix 'array declarator' 'allocatable'
is one that contains no dimension bound expressions.
It is called an allocatable array declarator because the dimension
bounds are specified at run-time in an
.kw ALLOCATE
statement.
.cp 7
.exam begin
DIMENSION A(:), B(:,:)
.
.
.
ALLOCATE( A(N) )
ALLOCATE( B(0:4,5) )
.exam end
.np
In the previous example,
.id A(:)
is a one-dimensional allocatable array declarator
and
.id B(:,:)
is a two-dimensional allocatable array declarator.
The first
.kw ALLOCATE
statement is used to allocate the array
.id A
with bounds
.id 1:N.
The second
.kw ALLOCATE
statement is used to allocate the array
.id B
with bounds
.id 0:4
in the first dimension
and
.id 1:5
in the second dimension.
.endlevel
.*
.section Classifying Array Declarators by Array Name
.*
.np
Array declarators can also be classified according to the characteristic
of the array name.
The following sections discuss the two classifications.
.beglevel
.*
.section Actual Array Declarator
.*
.np
.ix 'actual array declarator'
.ix 'array declarator' 'actual'
An
.us actual array declarator
is one in which the array name is not a dummy argument.
All actual array declarators must also be constant array declarators.
An actual array declarator is permitted in a
.kw DIMENSION
statement, a type statement or a
.kw COMMON
statement.
.*
.section Dummy Array Declarator
.*
.np
A
.us dummy array declarator
.ix 'dummy array declarator'
.ix 'array declarator' 'dummy'
is one in which the array name is a dummy argument and hence can only
appear in a function or subroutine subprogram.
It can be a constant, adjustable or assumed-size array declarator.
A dummy array declarator can appear in a
.kw DIMENSION
statement or a type statement but not in a
.kw COMMON
statement.
It should be noted that the array declarator for a dummy array
declarator need not be the same as the array declarator of the
corresponding actual array declarator.
Also note that every array declarator in a main program must be a
constant array declarator.
.endlevel
.*
.section Use of Array Names
.*
.np
The appearance of an array name must always be as part of an array
element name except in the following cases:
.autonote
.note
in a list of dummy arguments.
For example, a subroutine that has as one of its arguments an array.
.note
in a
.kw COMMON
statement to define that array as belonging to a common block.
.note
in a type statement either as part of an array declarator or by itself
to establish the type of the array.
.note
in an array declarator in a
.kw DIMENSION,
type or
.kw COMMON
statement.
.note
in an
.kw EQUIVALENCE
statement.
.note
in a
.kw DATA
statement.
.note
in the list of actual arguments when calling an external procedure.
.note
In the list of an input/output statement.
.note
as a unit identifier for an internal file in an input/output
statement.
.note
as a format identifier in an input/output statement.
.note
in a
.kw SAVE
statement.
.endnote
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -