To: J3 J3/19-148 From: Van Snyder Subject: Specified-rank variables Date: 2019-February-13 References: 19-110r1, 19-142 Introduction ============ Paper 19-142 introduces the facility to declare an object to have the same declared type and kind as another object. It remarks "not rank or shape (some future paper should perhaps address those)." Paper 19-110r1 addresses those. 19-110r1 uses a arrays to specify all bounds, which arrays could be the result of LBOUND or UBIUND intrinsic functions. It uses a RANK declaration to specify the rank but not bounds, without explaining it in sufficient detail. Proposed functionality ====================== Provide a declaration of the rank of an array. If the rank is not zero, it specifies that a dummy argument is assumed shape with lower bounds all 1, or that a local array is deferred shape, with the specified rank. If the rank is zero, it declares a scalar, not an assumed-shape or deferred-shape object. There is a RANK intrinsic function to inquire the rank of an object. Paper 19-110r1 used the same spelling for the declaration, but there are two necessary purposes. One is to specify that the rank of a declared object is the same as another object. Another is to specify the rank using a scalar integer constant expression, for example, a parameter of a parameterized module. If the argument of the RANK intrinsic function is a scalar integer constant, its result is zero. Proposed syntax =============== Use RANK(A), not as a reference to the intrinsic function but as an attribute specification in the declaration of an object B, to declare it has the same rank as A, e.g., real, rank(a) :: B ! Either assumed or deferred shape, same rank as A, ! except if A is scalar, B is also a scalar. Use RANKIS(N) as an attribute in the declaration of an object B to declare its rank, e.g., real, rankis(3) :: B ! Either assumed or deferred shape, rank is 3 or real, rankis(r) :: B ! Either assumed or deferred shape, rank is r>0, ! where R might be a parameter of a parameterized ! module. If R is zero, B is a scalar. These attribute specifications should also be allowed for component definitions. Alternatives ============ Use RANKOF instead of RANK to specify the rank is the same as another object, to avoid confusion with the RANK intrinsic function, e.g., real, rankof(a) :: B ! Same as first example above Always use RANKIS as the attribute specification, and use the RANK intrinsic function to inquire the rank of another object, e.g., real, rankis(rank(a)) :: B ! Same as first example above, but more ! verbose