主题:调用子程序出错,怎么会这样呢
程序很简单,我调用lapack里的子程序来求矩阵的逆矩阵,下面写法程序可以通过:
program main
implicit none
complex*16::a(3,3),b(3,3),c(3,3)
data a/10,2.5,(3,7),4,5,6,7,8,9/
print*,'a='
write(*,'(3(F8.4,"+i",F8.4,", "))') , a(1,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , a(2,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , a(3,:)
call zInverse(3,a,b)
print*,'b='
write(*,'(3(F8.4,"+i",F8.4,", "))') , b(1,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , b(2,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , b(3,:)
c=matmul(a,b)
print*,'c='
write(*,'(3(F8.4,"+i",F8.4,", "))') , c(1,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , c(2,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , c(3,:)
!contains
end
subroutine zInverse(n, a, ra)
integer::n,lda,ipiv(n),info,lwork
complex*16::a(n,n),ra(n,n),work(n)
ra=a
lwork=n
lda=n
call zgetrf(n, n, ra, lda, ipiv, info)
if(info/=0) write(0,*) 'Error occured in zgetrf!'
call zgetri(n, ra, lda, ipiv, work, lwork, info)
if(info/=0) write(0,*) 'Error occured in zgetri!'
end
但是如果在子程序上做点变动
subroutine zInverse(n, a,n, ra,n)
就有问题了,说什么属性冲突!!
怎么回事了?谁知道啊?
错误 1 error #6406: Conflicting attributes or multiple declaration of name. [N]
program main
implicit none
complex*16::a(3,3),b(3,3),c(3,3)
data a/10,2.5,(3,7),4,5,6,7,8,9/
print*,'a='
write(*,'(3(F8.4,"+i",F8.4,", "))') , a(1,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , a(2,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , a(3,:)
call zInverse(3,a,b)
print*,'b='
write(*,'(3(F8.4,"+i",F8.4,", "))') , b(1,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , b(2,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , b(3,:)
c=matmul(a,b)
print*,'c='
write(*,'(3(F8.4,"+i",F8.4,", "))') , c(1,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , c(2,:)
write(*,'(3(F8.4,"+i",F8.4,", "))') , c(3,:)
!contains
end
subroutine zInverse(n, a, ra)
integer::n,lda,ipiv(n),info,lwork
complex*16::a(n,n),ra(n,n),work(n)
ra=a
lwork=n
lda=n
call zgetrf(n, n, ra, lda, ipiv, info)
if(info/=0) write(0,*) 'Error occured in zgetrf!'
call zgetri(n, ra, lda, ipiv, work, lwork, info)
if(info/=0) write(0,*) 'Error occured in zgetri!'
end
但是如果在子程序上做点变动
subroutine zInverse(n, a,n, ra,n)
就有问题了,说什么属性冲突!!
怎么回事了?谁知道啊?
错误 1 error #6406: Conflicting attributes or multiple declaration of name. [N]