我希望在Fortran中创建具有多个分配级别的锯齿状数组。但是,我的构造函数和析构函数过程都遇到“在(1)处没有通用'new'的特定子例程”的错误。
我在Fotran刚起步,现在已经坚持了很多小时。我相信问题是我的第一个参数“ 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
在这种情况下,调试错误消息的最佳方法是调用实际的特定子例程。这意味着要调用NewMatrix
而不是Matrix
。
那么你会得到
call NewMatrix(M1, 10)
1
Error: Actual argument for ‘matrix’ must be ALLOCATABLE at (1)
jagged.f90:51:18:
call DeleteMatrix(M1, 10)
1
Error: Actual argument for ‘matrix’ must be ALLOCATABLE at (1)