title: Return type mismatch of function
body: <p>I want to diagonalize a complex matrix in fortran90 with a function. This is the function I use</p>
  
  <pre><code>!==========================================================================
  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
  </code></pre>
  
  <p>and I simply call it with</p>
  
  <pre><code>Wmattemp=inv(Wmattemp,nsit)
  </code></pre>
  
  <p>where its type is</p>
  
  <pre><code>complex*16, allocatable :: Wmattemp(:,:)
  </code></pre>
  
  <p>But I obtain this error when I compile with </p>
  
  <pre><code>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
  </code></pre>
  
  <p>II'm not a fortran expert so I cannot find what is the problem.</p>
  
  <p>Now I added to the main program</p>
  
  <pre><code>complex*16, allocatable :: inv(:,:)
  </code></pre>
  
  <p>but I obtain this error</p>
  
  <pre><code>code.f90:217.13:
  
         A=inv(Wmattemp,nsit)
               1
  Error: Array index at (1) must be of INTEGER type, found COMPLEX
  </code></pre>