Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compilation 错误:参数中的类型不匹配';res';at(1);将类型(矩阵)传递到类型(矩阵)_Compilation_Fortran_Gfortran - Fatal编程技术网

Compilation 错误:参数中的类型不匹配';res';at(1);将类型(矩阵)传递到类型(矩阵)

Compilation 错误:参数中的类型不匹配';res';at(1);将类型(矩阵)传递到类型(矩阵),compilation,fortran,gfortran,Compilation,Fortran,Gfortran,我发现了以下编译错误: ./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)变量传递给另一个模块中声明的函数,该模块使用Ty

我发现了以下编译错误:

./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
中的类型声明就可以了。在我的代码中,我通常为多个模块之间共享的类型提供专用模块

请插入相关代码,包括调用例程的位和例程本身,好吗?确保包含所有变量的声明。还有,派生类型是如何定义的,在哪里定义的?我很快编辑了文本,所以只有时间来提示-readmatrix如何知道矩阵是什么?readmatrix在io模块中,在隐式noneSo之前使用了Mathmodule。所以,我想我发现了问题。我将矩阵类型的声明放在一个单独的模块中。问题在于编译步骤,而不是代码本身。然而,坦克堡旅游快速反应。我正要回答几乎相同的事情,但我会在这里评论一个补充我要做的。有时,这种“重复”的定义很好,但这不是其中之一。