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.

.



Relevant Pages

  • Re: COBOL intrinsic functions
    ... If your compiler does NOT have this function, ... I couldn't find anything on exception handling for intrinsic functions, ... The intrinsic function corrrectly picked up the date as an error... ... It would be SO good if COBOL had a simple date validation intrinsic... ...
    (comp.lang.cobol)
  • Re: Compiled code
    ... _lrotr may be an intrinsic function. ... >> would compile directly to native code (codeable in assembler I suppose) ... > Or compiler might place code of _lrotr into caller function. ...
    (microsoft.public.vc.language)
  • Re: Compiled code
    ... Vladimir ... > _lrotr may be an intrinsic function. ... >> Or compiler might place code of _lrotr into caller function. ...
    (microsoft.public.vc.language)
  • Re: the transfer of two dimension array
    ... Compiling file: array1.f95 ... The problem is that the compiler didn't ... but as the intrinsic function REAL() which isn't allowable in the ...
    (comp.lang.fortran)
  • Re: Question about intel_VEC_memcpy
    ... Syntax such as array assignment and matmul() is highly productive of temporaries, some of which could be avoided by better optimization in the compiler. ... If you are willing to work with a current version of ifort, and to submit a case to Intel support, there is likely to be scope for improvement. ... a compiler can't avoid the allocation of a temporary array for the intermediate result. ...
    (comp.lang.fortran)