J3/03-118r1 To: J3 From: UK Fortran panel Subject: Edits for UK comment TC10 (Allocatable array assignment) Date: 26th February 2003 Comment TC10 of the UK vote was: Treat the assignment to an allocatable array in the same way as to an allocatable array component Allocatable array assignment should be user-friendly the same way that allocatable component assignment is; that is, the destination array should be reallocated to the correct shape if it is of the incorrect shape. Thus, instead of having to say: DEALLOCATE (A) ALLOCATE (A(SIZE(COMPRESS(B)))) A = COMPRESS(B) one should be able to say A = COMPRESS(B) and have the same effect (except that if A has the TARGET attribute and is already the same size as COMPRESS(B), it should be reused rather than go through the allocate-deallocate cycle - for compatibility with F90/95). For consistency, the above should apply to allocatable scalars (with deferred type parameters) as well as to allocatable arrays. I.e. Treat the assignment to an allocatable variable in the same way as to an allocatable component. Allocatable variable assignment should be user-friendly the same way that allocatable component assignment is; that is, a destination array should be reallocated to the correct shape if it is of the incorrect shape, and if the destination has deferred type parameters, it should be reallocated to have the correct values. A scalar example is that for CHARACTER(:),ALLOCATABLE :: A,B instead of DEALLOCATE(A) ALLOCATE(CHARACTER(LEN(B))::A) A = B one should be able to say A = B and have the same effect. Here are the edits for this: 32:25. Change "a derived-type" to "an". {Deferred type parameters will now be able to change even for intrinsic assignment statements.} 32:25. Change reference 7.4.1.2 to 7.4.1.3 {Because 7.4.1.3 is where this is described. NOTE: This edit should be done even if the rest of the paper is not.} 139:7. Replace the line by (2) Either shall be an allocatable array of the same rank as or the shapes of and shall conform, and 139:9+7. Last line of Table 7.8. Add "kind" before "type parameters". and after "" add "; each nonkind type parameter value shall be the same unless is allocatable and the corresponding type parameter is deferred" {NOTE: "nonkind" should probably be "length" or whatever else is decided.} 139:28+. Add paragraph and note "If is an allocated allocatable variable, it is deallocated if is an array of different shape or any of the corresponding nonkind type parameter values of and differ. If is or becomes an unallocated allocatable variable, it is allocated with the dynamic type and type parameters of , the shape of , and with each lower bound (if any) equal to the corresponding element of LBOUND(). Note 7.34a For example, given the declaration CHARACTER(:),ALLOCATABLE :: NAME then after the assignment statement NAME = 'Dr. '//FIRST_NAME//' '//SURNAME NAME will have the length LEN(FIRST_NAME)+LEN(SURNAME)+5, even if it had previously been unallocated, or allocated with a different length. However, for the assignment statement NAME(:) = 'Dr. '//FIRST_NAME//' '//SURNAME NAME must already be allocated at the time of the assignment; the assigned value is truncated or blank padded to the previously allocated length of NAME." 140:4+4+. Append to note 7.36 "If C is an allocatable array of rank 1, then C = PACK(ARRAY,ARRAY>0) will cause C to contain all the positive elements of ARRAY in array element order; if C is not allocated or is allocated with the wrong size, it will be re-allocated to be of the correct size to hold the result of PACK." ===END===