miro
miro

Reputation: 809

ifort -> gfortran: array - Incompatible ranks 2 and 1 in assignment at (1)

I'm trying to move below Intel Fortran line to gfortran, but I get following error:

DOUBLE PRECISION, DIMENSION(0:0,0:0) :: value = (/ -999D99 /)

Incompatible ranks 2 and 1 in assignment at (1)

If I understand it correctly, we are creating a 2-dim array with 1 element. I came with following fix. Is this standard conforming?

DOUBLE PRECISION, DIMENSION(0:0,0:0) :: value = reshape ((/-999D99/), shape(value))

Upvotes: 0

Views: 564

Answers (1)

It is not allowed to make an assignment (even in initialization) between arrays of different ranks. Therefore the line

...DIMENSION(0:0,0:0) :: value = (/ -999D99 /)

is illegal.

Reshaping the right hand side to an array of rank 2

...DIMENSION(0:0,0:0) :: value = reshape ((/-999D99/), shape(value))

is a standard conforming solution, but it is easier to assign a scalar:

...DIMENSION(0:0,0:0) :: value = -999D99

Of course, this will work only if you have just 1 value. It will be assigned to all elements of the array on the left hand side.

Upvotes: 1

Related Questions