我希望在FORTRAN中创建锯齿状数组,但收到“在(1)处通用'new'没有特定的子例程”]

问题描述 投票:0回答:1

我希望在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
fortran jagged-arrays allocatable-array
1个回答
0
投票

在这种情况下,调试错误消息的最佳方法是调用实际的特定子例程。这意味着要调用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)
© www.soinside.com 2019 - 2024. All rights reserved.