J3/15-240r4 To: J3 From: Malcolm Cohen & Stan Whitlock Subject: Revised edits paper for US-27 Date: 2015 October 13 1. Introduction US-27, SELECT RANK, was adopted by WG5 at J3 meeting 207 (see N2073), and the Specs, Syntax and Edits from 15-142r2 were agreed by J3 (see 15-215). However, the editor overlooked this paper when producing 15-007r2. This paper contains a revised version of the edits, adjusted for applying to 15-007r2. Also, the edits in that paper to 8.1.3.3 "Other attributes of associate names" seem insufficient, so they have been elaborated here. 2. Edits to 15-007r2 [xviii] Introduction, Data usage and computation, add new feature "The SELECT RANK construct provides structured access to the elements of an assumed-rank array.". [4:38] After "," add ", ,". {SELECT RANK and END SELECT RANK can be branch targets.} [31:26-] 2.1 High level syntax, R213 executable-construct, Before "<> " Insert "<> ". {Add the construct to the high-level syntax.} [35:16] replace "SELECT CASE constructs, and" by "SELECT CASE constructs, SELECT RANK constructs, and" {add recent new item to list} [98:4] 5.5.8.5 Assumed-size array, p1, After "effective argument", insert ", or the associate name of a RANK (*) block in a SELECT RANK construct". {New class of assumed-size array.} [99:8] 5.5.8.7 Assumed-rank entity, p1 After "effective argument" insert ", or the associate name of a RANK DEFAULT block in a SELECT RANK construct". {New class of assumed-rank entity.} [99:15-16] Same subclause, C539 "or the first" -> "the first", After "inquiry function" insert ", or the selector of a SELECT RANK statement". {Allow assumed-rank object in SELECT RANK.} [169:10+] 8.1.1 Blocks, p1, bullet list, After "SELECT CASE construct;" Insert new bullet "SELECT RANK construct;". {Add to list of constructs containing blocks.} {Strategy for modifying 8.1.3.3: split p1 up into 2 paragraphs, one which applies to all the association constructs, the other of which applies only to ASSOCIATE and SELECT TYPE. [170:34] 8.1.3.3 Other attributes of associate names, p1, Delete "and corank". {This will reappear later.} [171:1-3] Delete "The cobounds ... has the attribute." {This will reappear later.} [170:4] After "or POINTER attribute." insert paragraph break and new text: "Within an ASSOCIATE, SELECT RANK, or SELECT TYPE construct, each associating entity has the same corank as its associated selector." [-] Then insert the deleted sentences from [171:1-3] "The ... attribute.". {Reinstate text to apply to all association constructs.} This should make p1 and p2 read as follows: "Within an ASSOCIATE or SELECT TYPE construct, each associating entity has the same rank as its associated selector. The lower bound of each dimension is the result of the intrinsic function LBOUND (13.8.101) applied to the corresponding dimension of selector. The upper bound of each dimension is one less than the sum of the lower bound and the extent. The associating entity has the TARGET attribute if and only if the selector is a variable and has either the TARGET or POINTER attribute. Within an ASSOCIATE, SELECT RANK, or SELECT TYPE construct, each associating entity has the same corank as its associated selector. The cobounds of each codimension of the associating entity are the same as those of the selector. The associating entity has the ASYNCHRONOUS or VOLATILE attribute if and only if the selector is a variable and has the attribute. If the associating entity is polymorphic, it assumes the dynamic type and type parameter values of the selector. If the selector has the OPTIONAL attribute, it shall be present. The associating entity is contiguous if and only if the selector is contiguous." [184:1-] Immediately before 8.1.9 SELECT TYPE construct, insert new subclause " 8.1.8a SELECT RANK construct 8.1.8a.1 Purpose and form of the SELECT RANK construct The SELECT RANK construct selects for execution at most one of its constituent blocks. The selection is based on the rank of an assumed-rank variable. A name is associated with the variable (16.4, 16.5.1.6), in the same way as for the ASSOCIATE construct. R842a <> [ ]... R842b <> [ : ] SELECT RANK ( [ ] ) C839a (R842b) The in a shall be the name of an assumed-rank array. R842c <> RANK ( ) [ ] <> RANK ( * ) [ ] <> RANK DEFAULT [ ] C839b (R842c) A in a shall be non-negative and less than or equal to the maximum rank supported by the processor. C839c (R842a) For a given , the same rank value shall not be specified in more than one . C839d (R842a) For a given , there shall be at most one RANK ( * ) and at most one RANK DEFAULT . C839e (R842a) If appears on a the corresponding shall specify the same . C839f A SELECT RANK construct shall not have a that is RANK ( * ) if the selector has the ALLOCATABLE or POINTER attribute. R842d <> END SELECT [ ] C839g If the of a specifies a , the corresponding shall specify the same . If the of a does not specify a , the corresponding shall not specify a . The associate name of a SELECT RANK construct is the if specified; otherwise it is the name that constitutes the selector. 8.1.8a.2 Execution of the SELECT RANK construct A SELECT RANK construct selects at most one block to be executed. During execution of that block, the associate name identifies an entity which is associated (16.5.1.6) with the selector. A RANK ( * ) statement matches the selector if the selector is argument associated with an assumed-size array. A RANK ( ) statement matches the selector if the selector has that rank and is not argument associated with an assumed-size array. A RANK DEFAULT statement matches the selector if no other of the construct matches the selector. If a matches the selector, the block following that statement is executed; otherwise, control is transferred to the . It is permissible to branch to an only from within its SELECT RANK construct. 8.1.8a.3 Attribute of a SELECT RANK associate name Within the block following a RANK DEFAULT statement, the associating entity (16.5.5) is assumed-rank and has exactly the same attributes as the selector. Within the block following a RANK ( * ) statement, the associating entity has rank 1 and is assumed-size, as if it were declared with DIMENSION(1:*). Within the block following a RANK ( ) statement, the associating entity has the specified rank; the lower bound of each dimension is the result of the intrinsic function LBOUND (13.7.91) applied to the corresponding dimension of the selector, and the upper bound of each dimension is the result of the intrinsic function UBOUND (13.7.176) applied to the corresponding dimension of the selector. If the selector has the ALLOCATABLE attribute, the associating entity has that attribute. If the selector has the POINTER attribute, the associating entity has that attribute (and not the TARGET attribute). The other attributes of the associating entity are described in 8.1.3.3. 8.1.8a.4 Examples of the SELECT RANK construct This example shows how to use a SELECT RANK construct to process scalars and rank-2 arrays; anything else will be rejected as an error. SUBROUTINE process(x) REAL x(..) ! SELECT RANK(x) RANK (0) x = 0 RANK (2) IF (SIZE(x,2)>=2) x(:,2) = 2 RANK DEFAULT Print *, 'I did not expect rank', RANK(y), 'shape', SHAPE(y) ERROR STOP 'process bad arg' END SELECT The following example shows how to process assumed-size arrays, including how to use sequence association if you want to do multi-dimensional processing of an assumed-size array. SELECT RANK (y => x) RANK (*) IF (RANK(x)==2) THEN ! Special code for the rank two case. CALL sequence_assoc_2(y, LBOUND(x,1), UBOUND(x,1), LBOUND(x,2)) ELSE ! We just do all the other ranks in array element order. i = 1 DO IF (y(i)==0) Exit y(i) = -y(i) i = i + 1 END DO END IF END SELECT ... CONTAINS ... SUBROUTINE sequence_assoc_2(a, lb1, ub1, lb2) REAL a(lb1:ub1,lb2:*) j = lb2 outer: DO DO i=lb1,ub1 IF (a(i,j)==0) EXIT outer a(i,j) = a(i,j)**2 END DO j = j + 1 IF (ANY(a(:,j))==0) EXIT j = j + 1 END DO outer END SUBROUTINE ". {The new construct.} [187:21] 8.2.1 Branch concepts, p1, Between "" and "" insert ", ". {Allow branching to SELECT RANK and its END SELECT.} [301:18] 12.5.2.5 Allocatable and pointer dummy variables, p3, In the first sentence, beginning "The rank", after "dummy argument" insert ", unless the dummy argument is assumed-rank". {This is repairing a bug in assumed-rank.} [305:36] 12.5.2.12 Argument presence and restrictions..., p3, item (10), "SELECT TYPE or ASSOCIATE" ->"ASSOCIATE, SELECT RANK, or SELECT TYPE". {Do not allow rank selection on absent dummies.} ===END===