To: J3 J3/20-115r1
From: Tom Clune and Van Snyder
Subject: Syntax for rank-independent bounds
Date: 2020-February-26
Reference: 18-007r1, 19-202r2
Introduction:
Paper 19-202r2 proposed requirements and specs for BOUNDS and RANK
attributes that expand the ability to declare arrays in a
rank-agnostic context. This paper proposes syntax for these features.
Proposed syntax:
- The keyword to specify bounds using arrays shall be BOUNDS. It
would be technically unambiguous to use DIMENSION instead, but the
the new keyword is clearer for users.
- The bounds specification shall be enclosed in parentheses after the
keyword.
- The keyword to specify rank using an integer shall be RANK.
- The rank shall be specified by a constant non-negative integer
expression enclosed in parentheses after the keyword.
- There is no BOUNDS statement nor RANK statement. These keywords
only appear inside type declaration statements.
Examples:
(1)
INTEGER, RANK(3), ALLOCATABLE :: X1
is equivalent to
INTEGER, ALLOCATABLE :: X1(:,:,:)
(2)
REAL, RANK(0) :: X2 ! scalar dummy
is equivalent to
REAL :: X2
where X2 is a scalar dummy data object
(3)
CHARACTER, BOUNDS([80,24]) :: X3 ! lower bounds are default (=1)
is equivalent to
CHARACTER, DIMENSION(80,24) :: X3
(4)
INTEGER, PARAMETER(*) :: UPPER = [10,10,10]
INTEGER, BOUNDS (0:UPPER) :: X4 ! implicit broadcast of lower
is equivalent to
INTEGER :: X4(0:10,0:10,0:10)
(5)
REAL, BOUNDS([1,2,3]:10) :: X5 ! implicit broadcast of upper
is equivalent to
REAL :: X5(1:10,2:10,3:10)
(6)
INTEGER :: LB(2)
INTEGER :: UB(2)
INTEGER, BOUNDS(LB:UB) :: X6A, X6B ! multiple declarations
is equivalent to
INTEGER, DIMENSION(LB(1):UB(1),LB(2):UB(2)) :: X6A, X6B
(7)
REAL, BOUNDS([1,1,1]:) :: X7 ! assumed shape dummy
declares an assumed shape dummy argument and is equivalent to
REAL :: X7(:,:,:)
(8)
INTEGER, BOUNDS([7,7,7]) :: X8A, X9B(10) ! array spec overrides bounds
declares one array of rank 3 and another array of rank 1. It is
equivalent to
INTEGER :: X8A(7,7,7), X9B(10)
Rules and constraints:
<> RANK ( )
Constraint: The value of in a
shall be nonnegative.
Constraint: If appears, then each declared entity
shall be a scalar dummy data object or have have the ALLOCATABLE
or POINTER attribute.
<>
<>
<> BOUNDS ( )
<>
<> :
<> :
<> :
<> :
<> is
Constraint: If both specifiers in are
, they shall have the same size.
<> BOUNDS ( : )
Constraint: shall be an constant size, rank 1,
integer array.
Constraint: If the specifier is , then
every declared object shall be a dummy data object.
If only one expression appears in , it
specifies the rank and upper bounds of the array. The rank is the size
of the .
If an expression appears before a colon in it
specifies the lower bounds of the array. Otherwise, the lower bounds
are implicitly 1 in each dimension.
If two expressions appear in and one is a
scalar, it is broadcast to the shape of the other.
If the size of an specifier is zero, then it
declares a scalar.
===END===