Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "array cannot have a deferred shape" mean in fortran?

I have a simple fortran function that computes the Kronecker product:

function kron(A, B)
    implicit none
    real, intent(in) :: A(:, :), B(:, :)
    integer :: i, j, ma, na, mb, nb
    real, dimension(:, :) :: kron

    ma = ubound(A, 1)
    na = ubound(A, 2)
    mb = ubound(b, 1)
    nb = ubound(b, 2)
    forall(i=1:ma, j=1:na)
        kron(mb*(i-1)+1:mb*i, nb*(j-1)+1:nb*j) = A(i,j)*B
    end forall
end function kron

It's inside a module, but when I compile it with gfortran -static -ffree-form -std=f2003 -Wall, I get these errors:

function kron(A, B)
                1
Error: Array 'kron' at (1) cannot have a deferred shape

Is this error occurring because you're supposed to know the size of the array to be returned beforehand?

like image 390
Michael A Avatar asked Sep 12 '13 16:09

Michael A


1 Answers

That is exactly what the error is telling you: kron must have an explicit shape. If you do not want to pass the array sizes beforehand, you'd have to define kron as

real, dimension(lbound(a,dim=1):ubound(a,dim=1),&
                lbound(a,dim=2):ubound(a,dim=2)) :: kron

Using this particular explicit declaration above does compile for me on gfortran 4.6.3.

like image 92
Kyle Kanos Avatar answered Sep 30 '22 20:09

Kyle Kanos