ナビゲーション:前へ 上へ 次へ
例:
ナビゲーション:前へ 上へ 次へ
3.1 割付け仮配列
仮引数は割付け配列として宣言可能です。例:
SUBROUTINE s(dum) REAL,ALLOCATABLE :: dum(:,:) ... END SUBROUTINE
割付け仮引数を持つということは、 どのような参照に対しても明示的な引用仕様が必要であることを意味します。 すなわち手続きが内部手続きもしくはモジュール手続きでない場合には、 その手続きを参照するすべてのルーチンにおいて参照可能な引用仕様ブロックが必要です。
割付け仮配列に渡されるどのような実引数もまた割付け配列でなければなりません。
そして同じ型、種別型パラメタ、次元数を持っていなくてはなりません。
例:
REAL,ALLOCATABLE :: x(:,:) CALL s(x)
実引数(引数の割付けもしくは解放を行うものも含む)
は手続き呼出し前に割付けられている必要はありません。
例:
PROGRAM example2 REAL,ALLOCATABLE :: x(:,:) OPEN(88,FILE='myfile',FORM='unformatted') CALL read_matrix(x,88) ! ... process x in some way ! REWIND(88) CALL write_and_delete_matrix(x,88) END ! MODULE module CONTAINS ! ! This procedure reads the size and contents of an array from an ! unformatted unit. ! SUBROUTINE read_matrix(variable,unit) REAL,ALLOCATABLE,INTENT(OUT) :: variable(:,:) INTEGER,INTENT(IN) :: unit INTEGER dim1,dim2 READ(unit) dim1,dim2 ALLOCATE(variable(dim1,dim2)) READ(unit) variable CLOSE(unit) END SUBROUTINE ! ! This procedures writes the size and contents of an array to an ! unformatted unit, and then deallocates the array. ! SUBROUTINE write_and_delete_matrix(variable,unit) REAL,ALLOCATABLE,INTENT(INOUT) :: variable(:,:) INTEGER,INTENT(IN) :: unit WRITE(unit) SIZE(variable,1),SIZE(variable,2) WRITE(unit) variable DEALLOCATE(variable) END SUBROUTINE END
ナビゲーション:前へ 上へ 次へ