Inquiry Intrinsic Function (Generic): Returns the shape of an array or scalar argument.
Syntax
Results:
The result is a rank-one integer array whose size is equal to the rank of source. If kind is present, the kind parameter of the result is that specified by kind; otherwise, the kind parameter of the result is that of default integer. If the processor cannot represent the result value in the kind of the result, the result is undefined.
The value of the result is the shape of source.
The setting of compiler options that specify integer size can affect the result of this function.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: SIZE
Examples
SHAPE (2) has the value of a rank-one array of size zero.
If B is declared as B(2:4, -3:1), then SHAPE (B) has the value (3, 5).
The following shows another example:
INTEGER VEC(2)
REAL array(3:10, -1:3)
VEC = SHAPE(array)
WRITE(*,*) VEC ! prints 8 5
END
!
! Check if a mask is conformal with an array
REAL, ALLOCATABLE :: A(:,:,:)
LOGICAL, ALLOCATABLE :: MASK(:,:,:)
INTEGER B(3), C(3)
LOGICAL conform
ALLOCATE (A(5, 4, 3))
ALLOCATE (MASK(3, 4, 5))
! Check if MASK and A allocated. If they are, check
! that they have the same shape (conform).
IF(ALLOCATED(A) .AND. ALLOCATED(MASK)) THEN
B = SHAPE(A); C = SHAPE(MASK)
IF ((B(1) .EQ. C(1)) .AND. (B(2) .EQ. C(2)) &
.AND. (B(3) .EQ. C(3))) THEN
conform = .TRUE.
ELSE
conform = .FALSE.
END IF
END IF
WRITE(*,*) conform ! prints F
END