Error: Type mismatch in argument 'res' at (1); passed TYPE(matrix) to TYPE(matrix)

Error: Type mismatch in argument 'res' at (1); passed TYPE(matrix) to TYPE(matrix)

我发现了以下编译错误:

./src/MathModule.f90:85.18: call ReadMatrix(M1)
              1

Error: Type mismatch in argument 'res' at (1); passed TYPE(matrix) to TYPE(matrix)

我在 MathModule.f90 中声明了 Type(Matrix),我只是将 MathModule.f90 中的 Type(Matrix) 变量传递给另一个模块中声明的函数,该函数用作输入 Type(Matrix)

有什么想法吗?

MathModule.f90 文件:

module MathModule
use HelpModule
use InputOutputModule
implicit none
private
save

public Full, MatProd, Matrix, dp, MatrixProduct, SVD, Solve, maxerror, pi

! Defines IEEE Double Precision: 53 fractionbits ~= 15.995 decimal digits.
integer, parameter :: dp = SELECTED_REAL_KIND(15)   
! Defines the error to check floatingpoint equality on.
real(dp) :: maxerror = 0.0000001
! Defines pi with max precision possible.
real(dp), parameter :: pi = 4.0*atan(1.0)

! Defines the Matrix type:
!   A matrix can contain matrices A, B and M.
!   A and B are the lowrank representation and M is the fullrank representation.
!   The dimensions are of M.
!   The rank is of A and B and is -1 for a full matrix. 
type Matrix
    real(dp), allocatable :: A(:,:), B(:,:), M(:,:)
    integer :: rowDimension, columnDimension, rank
end type

contains


! Subroutine to setup the environment for the full command. After the setup, the
! subroutine calls the subroutines necessary for this command. After all operations are
! done, everything is teared down properly.
! @post For correct input at stdin this matrix is converted into a full matrix at stdout.
! @error If the matrix at stdin is not a rank-k matrix the help will be displayed.
subroutine Full()
    type(Matrix) :: Mat

    call ReadMatrix(Mat)
    if(Mat%rank == -1) then
        ! If rank = -1 then the matrix at stdin is not a rank-k matrix.
        call PrintHelp('The matrix at stdin is not a rank-k matrix!')
    else
        ! First allocate the full matrix of Mat, calculate it, set the
        ! rank to -1 (now Mat is a full matrix) and deallocate A and B
        ! because in write only the full matrix of Mat will be
        ! deallocated.          
        allocate(Mat%M(Mat%rowDimension, Mat%columnDimension))
        call MatrixProduct(Mat%A, Mat%B, Mat%M, 'N', 'T')
        Mat%rank = -1
        deallocate(Mat%A)
        deallocate(Mat%B)           
    endif
    call WriteMatrix(Mat)
end subroutine

调用ReadMatrix(mat)时出错:

subroutine ReadMatrix(res, fromUnit) 
    integer, intent(in), optional :: fromUnit
    type(Matrix) :: res

我猜你在 InputOutputModule 上也声明了 type Matrix(因为你指定 Readmatrix 也在那里)。 因此,两种不同的类型具有相同的名称(巧合的是共享相同的名称和属性)。

只需删除 MathModule 中的类型声明并使用 InputOutputModule 中的类型声明即可。在我的代码中,我通常有专门的模块用于在多个模块之间共享的类型。