想定サイズ配列は、仮引き数配列で、関連した実配列からサイズを継承しますが、ランクとエクステントは異なる場合があります。想定サイズ配列は、サブプログラムの中でのみ宣言できます。
Assumed_size_spec |
---|
>>-+----------------------------------------+--+----------------+--*->< | .-,-------------------------------. | '-lower_bound--:-' | V | | '---+----------------+--upper_bound-+--,-' '-lower_bound--:-' |
いずれかの境界が定数ではない場合、その配列はサブプログラム内で宣言してください。また、定数以外の境界はサブプログラムの入り口で決められます。 下限が省略されると、そのデフォルト値は 1 となります。
最終の次元は上限を持たず、代わりに、アスタリスクによって指定されます。 エレメントに対する参照が実配列の最後を過ぎないようにしてください。
ランクは、その宣言において、upper_bound 指定の数に 1 を加えたものに等しくなります。このランクは、それが関連した実配列のランクとは異なることもあります。
サイズは、想定サイズ配列が関連した実引き数から想定されます。
仮引き数配列のサイズは、以下のようになります。
MAX( INT (T - A + 1) / S, 0 )
たとえば、次のようになります。
CHARACTER(10) A(10) CHARACTER(1) B(30) CALL SUB1(A) ! Size of dummy argument array is 10 CALL SUB1(A(4)) ! Size of dummy argument array is 7 CALL SUB1(A(6)(5:10)) ! Size of dummy argument array is 4 because there ! are just under 4 elements remaining in A CALL SUB1(B(12)) ! Size of dummy argument array is 1, because the ! remainder of B can hold just one CHARACTER(10) END ! element. SUBROUTINE SUB1(ARRAY) CHARACTER(10) ARRAY(*) ... END SUBROUTINE
INTEGER X(3,2) DO I = 1,3 DO J = 1,2 X(I,J) = I * J ! The elements of X are 1, 2, 3, 2, 4, 6 END DO END DO PRINT *,SHAPE(X) ! The shape is (/ 3, 2 /) PRINT *,X(1,:) ! The first row is (/ 1, 2 /) CALL SUB1(X) CALL SUB2(X) END SUBROUTINE SUB1(Y) INTEGER Y(2,*) ! The dimensions of y are the reverse of x above PRINT *, SIZE(Y,1) ! We can examine the size of the first dimension ! but not the last one. PRINT *, Y(:,1) ! We can print out vectors from the first PRINT *, Y(:,2) ! dimension, but not the last one. END SUBROUTINE SUBROUTINE SUB2(Y) INTEGER Y(*) ! Y has a different rank than X above. PRINT *, Y(6) ! We have to know (or compute) the position of ! the last element. Nothing prevents us from ! subscripting beyond the end. END SUBROUTINE
注:
! A is an assumed-size array.
PRINT *, UBOUND(A,1) ! OK - only examines upper bound of first dimension. PRINT *, LBOUND(A) ! OK - only examines lower bound of each dimension. ! However, 'B=UBOUND(A)' or 'A=5' would reference the upper bound of ! the last dimension and are not allowed. SIZE(A) and SHAPE(A) are ! also not allowed.
! A is a 2-dimensional assumed-size array PRINT *, A(:, 6) ! Triplet with no upper bound is not last dimension. PRINT *, A(1, 1:10) ! Triplet in last dimension has upper bound of 10. PRINT *, A(5, 5:9:2) ! Triplet in last dimension has upper bound of 9.