想使用function回传一整个阵列而不是一个数值,不知到与法该怎么用
program main
real*8, allocatable :: a(:,:),a1(:,:))
integer*4 :: b=3
allocate (a(b,b),a1(b,b))
!allocate (a1(b,b))
allocate (a2(b,b))
a=0.d0; a1=0.d0;
a1(1,1:3)=1.5d0;
a(2,1:3)=2d0*a1(1,1:3)+5d0
write(*,*) a;
write(*,*) a1;
print * , '\'
write(*,*) add(b,a,a1)
pause
stop
end program main
function add(b,a,a1)
integer*4 :: b
real*8,allocatable :: a(:,:),a1(:,:)
allocate( a(b,b),a1(b,b) )
real*8, dimension(b,b) :: add
add=a+a1
return
end function add
跑出两个错误讯息,不知道与法该怎么用QQ
Error: A specification statement cannot appear in the executable section.
real*8, dimension(b,b) :: add
作者: terryys (terry) 2012-06-01 11:20:00
第二个错误其实就是第一个引起的,解决第一个就可以了但是副程式要用allocatable的话要加interface,或者把它用contains包在主程式内对了,你这个程式里还有另外的错误,但都容易解决