- 积分
- 20
- 注册时间
- 2003-9-14
- 仿真币
-
- 最后登录
- 1970-1-1
|
在子程序使用ALLOCATABLE可以吗?
为什么我的子程序中使用这个,编译的时候出现问题?
如果不能用的话
应该怎么办?
程序如下:
program test1
real,dimension(:,,allocatable::A1
real,dimension(:),allocatable::X1
real,dimension(:),allocatable::Y1
INTEGER m
allocate(A1(m,m+1))
allocate(X1(m))
allocate(Y1(m+1))
m=4
A1(1,1)=0.2368
A1(1,2)=0.2471
A1(1,3)=0.2568
A1(1,4)=1.2671
A1(1,5)=1.8471
A1(2,1)=0.1968
A1(2,2)=0.2071
A1(2,3)=1.2168
A1(2,4)=0.2271
A1(2,5)=1.7471
A1(3,1)=0.1581
A1(3,2)=1.1675
A1(3,3)=0.1768
A1(3,4)=0.1871
A1(3,5)=1.6471
A1(4,1)=1.1161
A1(4,2)=0.1254
A1(4,3)=0.1397
A1(4,4)=0.1490
A1(4,5)=1.5471
call gauss_3(m,A1,X1,Y1)
print *,(X1(i),i=1,m)
end
subroutine gauss_3(n,A,X,Y)
real,dimension(:,:),allocatable::A
real,dimension(:),allocatable::X
real,dimension(:),allocatable::Y
integer i,j,k,n
real sum
allocate(A(n,n+1))
allocate(X(n))
allocate(Y(n+1))
do i=1,n
do k=i+1,n
if(abs(A(i,i))<abs(A(k,i))) then
Y(i:n+1)=A(i,i:n+1)
A(i,i:n+1)=A(k,i:n+1)
A(k,i:n+1)=Y(i:n+1)
endif
enddo
do j=i+1,n
A(j,i:n+1)=A(j,i:n+1)-A(j,i)/A(i,i)*A(i,i:n+1)
enddo
enddo
X(n)=A(n,n+1)/A(n,n)
do i=n-1,1,-1
sum=0
do j=n,i+1,-1
sum=sum+A(i,j)*X(j)
enddo
X(i)=(A(i,n+1)-sum)/A(i,i)
enddo
end |
|