program test4 implicit none ! Variables real, allocatable :: x(:, :) ! Body of test4 allocate( x(100, 100) ) x = 1.0 call desub(x) print *, allocated(x) call alsub(x) print *, allocated(x) print *, x stop contains subroutine desub(x) real, allocatable, intent(in out) :: x(:, :) deallocate(x) return end subroutine desub subroutine alsub(x) real, allocatable, intent(out) :: x(:, :) allocate(x(2, 2)) x = 1.1 return end subroutine alsub
実行結果
F
T
1.100000 1.100000 1.100000 1.100000
intent(in) ではいじれない。intent(in out) の時は解放してもよい。intent(out) の時は、使うには割り付ける必要がある。