Following on from this question, I'm trying to create a derived type Result2D
that has a rank-2 array data
as a property, that is filled with data by a procedure init()
:
type, public :: Result2D
class(*), allocatable :: data(:,:)
contains
procedure, public :: init
end type
contains
subroutine init(this, data)
class(Result2D) :: this,
class(*) :: data(:,:)
allocate(this%data, source=data)
end subroutine
However, calling init with a rank-2 array results in an array bound mismatch error in GFortran, on the line with the allocate
statement: Array bound mismatch for dimension 1 of array '<<unknown>>' (4/2)
. I don't understand why this would be happening, and it works fine for rank-1 arrays (but not for anything rank-2 and above).
An example of the code calling init()
:
type(Result2D) :: r
integer :: i(2,2)
i(1,:) = [1,2]
i(2,:) = [3,4]
call r%init(i)