我希望在 Fortran 中创建具有多级分配的锯齿状数组。但是,对于我的构造函数和析构函数过程,我都遇到了“在 (1) 处没有通用'new' 的特定子例程”的错误。
我是 Fortran 的新手。我相信问题是我的第一个论点“M1”不适合。但是,我似乎无法弄清楚为什么。
module JaggedArrayModule
implicit none
save
private
public JaggedArray, New, Delete
type JaggedArray
private
real, allocatable :: vector(:)
end type
interface New
module procedure NewMatrix
end interface
interface Delete
module procedure DeleteMatrix
end interface
contains
subroutine NewMatrix(Matrix, maxsize)
type (JaggedArray), intent(out), allocatable :: Matrix(:)
integer :: maxsize, i
allocate(Matrix(maxsize))
do i=1, maxsize
allocate(Matrix(i)%vector(i))
enddo
end subroutine
subroutine DeleteMatrix(Matrix, maxsize)
type (JaggedArray), intent(inout), allocatable :: Matrix(:)
integer :: maxsize, i
do i=1, maxsize
deallocate(Matrix(i)%vector(i))
enddo
deallocate(Matrix)
end subroutine
end module
program main
use JaggedArrayModule
type (JaggedArray) :: M1(5)
call New(M1, 10)
call Delete(M1, 10)
end program