将类型传递给另一个模块中的子例程

时间:2017-11-23 14:27:17

标签: fortran fortran2003

我有一点问题我无法找到解决方案,但我确信有一个。 我在模块中定义了一个类型,并希望将该类型用作另一个模块中构造函数的参数。像这样的东西: 第一档:

module Simulation_mod
    use SolverParameters_mod
    type, public :: Simulation_class
        type(SolverParameters_class), public :: SolverParameters
    end type
    type(Simulation_class), public :: Simulation
end module

第二档:

module SolverParameters_mod
    implicit none
    type, public :: SolverParameters_class
        private
        real :: MaxRelError
        integer :: MaxNumberIter
        integer :: NumericalDamping
        real, dimension(:), allocatable :: InitialValue
    end type SolverParameters_class
end module

第三档:

module Solver_mod
use Simulation_mod
type, public :: Solver_class
    private
    real :: MaxRelError
    integer :: MaxNumberIter
    integer :: NumericalDamping
    real, dimension(:), allocatable :: InitialValue
end type Solver_class

interface Solver_class
module procedure InitSolver
end interface Solver_class

contains

subroutine InitSolver(VarSolverParameters)
    ! Declaring part
    type(Solver_class) :: Solver
    class(SolverParameters), intent(in) :: VarSolverParameters
    ! Executing part
    Solver%MaxRelError = VarSolverParameters%GetMaxRelError
    Solver%MaxNumberIter = VarSolverParameters%GetMaxNumberIter
    Solver%NumericalDamping = VarSolverParameters%GetNumericalDamping
    Solver%InitialValue = VarSolverParameters%GetInitialValue
end subroutine InitSolver
end module Solver_mod

正确定义了Getter函数。在尝试编译时,我得到error #6457: This derived type name has not been declared. [SOLVERPARAMETERS] class(SolverParameters), intent(in) :: VarSolverParameters --------------^

如何将对象SolverParameters传递给InitSolver类型的构造函数Solver_class

0 个答案:

没有答案