Initializing Fortran 2D Array

The following program compiles with ifort (version 12), but not with GFortran (before version 4.8):

PROGRAM TEST IMPLICIT NONE REAL,DIMENSION(2,2)::X=(/1,2,3,4/) WRITE(*,*) X END PROGRAM TEST 

GFortran gives an error

 REAL,DIMENSION(2,2)::X=(/1,2,3,4/) 1 Error: Incompatible ranks 2 and 1 in assignment at (1) 

Ifort compiles the program and gives the expected result. Is this a bug in GFortran or is Intel fortran just allowing initialization of a non-standard array?

+4
source share
1 answer

Rewrite the array declaration line as:

 REAL,DIMENSION(2,2) :: X = RESHAPE([1,2,3,4],[2,2]) 

The reason that ifort compiled it is a non-standard implementation. This is a way to initialize arrays of rank higher than 1.

+6
source

Source: https://habr.com/ru/post/1412053/


All Articles