함수를 사용하여 fortran90에서 복잡한 행렬을 대각 화하려고합니다. 이것은 내가 함수의 반환 형식 불일치
!==========================================================================
function inv(A,n)
Implicit none
integer :: n
complex*16, dimension(n,n):: A
complex*16, dimension(n,n):: inv
complex*16,allocatable,dimension(:)::WORK
integer,allocatable,dimension(:)::IPIV
integer i,j,info,error
allocate(WORK(n),IPIV(n),stat=error)
if (error.ne.0)then
print *,"error:not enough memory"
stop
end if
call ZGETRF(n,n,A,n,IPIV,info)
if(info .eq. 0) then
write(*,*)"succeded"
else
write(*,*)"failed"
end if
call ZGETRI(n,A,n,IPIV,WORK,n,info)
if(info .eq. 0) then
write(*,*)"succeded"
inv=A
else
write(*,*)"failed"
end if
!deallocate(A,IPIV,WORK,stat=error)
!if (error.ne.0)then
! print *,"error:fail to release"
! stop
!end if
end function inv
를 사용하고 난 단지 그 형태가
complex*16, allocatable :: Wmattemp(:,:)
입니다
Wmattemp=inv(Wmattemp,nsit)
로 전화를하지만
gfortran -fdefault-real-8 code.f90 -llapack
code.f90:217.19:
Wmattemp=inv(Wmattemp,nsit)
1
Error: Return type mismatch of function 'inv' at (1) (INTEGER(4)/COMPLEX(8))
code.f90:217.16:
Wmattemp=inv(Wmattemp,nsit)
1
Error: The reference to function 'inv' at (1) either needs an explicit INTERFACE or the rank is incorrect
로 컴파일 할 때 나는이 오류를 얻을 수있는 기능입니다
요새는 아닙니다. xpert 그래서 문제가 무엇인지 찾을 수 없습니다. , 당신은에서 함수 inv
의 반환 값을 선언 할 필요가
는 지금은 메인 프로그램
complex*16, allocatable :: inv(:,:)
에 추가하지만 모듈을 사용하지 않기 때문에이 오류
code.f90:217.13:
A=inv(Wmattemp,nsit)
1
Error: Array index at (1) must be of INTEGER type, found COMPLEX
거의 확실히 당신은 CALLING에서 inv를 선언하지 않았습니다. ite, 즉이 코드 조각에는 없지만 inv가 호출 된 곳입니다. 당신은 또한 모든 선언과 함께 그 코드 조각을 보여줄 수 있습니까? –
inv의 선언을 추가했지만 이제 다른 오류가 발생합니다. – user3368447
프로 시저 (서브 루틴 및 함수)를 하나 이상의 모듈에 배치하고 해당 모듈을 '사용'하는 것이 좋습니다. 그렇다면 함수를 선언 할 필요가 없습니다. 이렇게하면 인터페이스가 컴파일러에게 알려 지므로 인수 계약을 확인할 수 있습니다. 인터페이스를 작성하면 함수가 변경되면 함수, 호출 (들), 인터페이스 등 세 가지 사항을 변경할 수 있습니다. 모듈을 사용하면 함수와 호출 ( –