Re: the transfer of two dimension array




Elijah Cardon wrote:
"FX" <coudert@xxxxxxxxxxxxx> wrote in message
....
program main
real ::array_name(12,4) = reshape((/ (real(i), i = 1, 48) /), &
(/ 12, 4 /))
....

The snippet doesn't compile for me:
Compiling file: array1.f95
C:\Documents and Settings\All Users\Documents\fortran_stuff\array1.F95(3) :
error 921 - The REAL intrinsic function is not permitted in an
initialisation expression
Ideas? EC

Interesting, what compiler? The problem is that the compiler didn't
recognize the use of real() in the argument to reshape() as an array,
but as the intrinsic function REAL() which isn't allowable in the
context as the error indicated.

While the use of an intrinsic function as a variable name is allowable
(in at least most places) it isn't good practice leading to difficulty
in reading the code. Here it seems to have found a problem in the
compiler.

The workaround would be to use some other name for the temporary array
in the reshape() argument as in

real ::array_name(12,4) = reshape((/ (r(i), i = 1, 48) /), &
(/ 12, 4 /))

where I used "r" instead of "real".

The use of "implicit none" at the beginning would have caught this out
with a different message of not having defined real() and that might
have triggered the thought of not using the intrinsic name as a
variable originally.

.