數組作函數參數,必須在函數體內製定數組大小。之前的老fortran可以用*號代替下標,但是隻能應用在數組最後一維。如果有一個矩陣行數列數事先都不知道,這種方法就不行了。fortran95引入module之後,要實現動態數組做函數參數就簡單多了。樣例代碼如下:
module mytest
contains
subroutine test(ps)
integer,dimension(:,:)::Ps;
integer ::p;
p=size(ps);
write(*,*)p;
write(*,*) ps(1,1),ps(1,2),ps(2,1),ps(2,2)
end subroutine
end module
program farray
!real(kind(le0)):: s;
use mytest
!integer,allocatable,dimension(:)::s;
!allocate(s(10));
integer ,dimension(2,2)::arr;
arr(1,1) = 1.5
arr(1,2) = 2.5
arr(2,1) = 3.5
arr(2,2) = 4.5
write(*,*) arr(1,1),arr(1,2),arr(2,1),arr(2,2)
call test(arr);
end program farray