Silverfrost Forums

Welcome to our forums

Statement that does not compile

25 Jan 2013 9:13 #11490

In am expample I found on line the following statement does not compile

A = reshape([(real(i), i = 1, size(A))], shape(A))

I get an error about the [.

Is this an issue of something non standard.

A is definded as a 2 dimensional array and i as an integer initially.

Thanks.

Michaeal

25 Jan 2013 9:57 #11491

The use of [ ] to delimit an array is a Fortran 2003 feature.

You can either enable the compiler option /F2K to allow this feature to be used or replace [ ] with (/ /) to use the Fortran 90 equivalent.

For example, the following should compile:

program main
   integer i
   real A(2,2)
   A = reshape((/(real(i), i = 1, size(A))/), shape(A))
end
28 Jan 2013 2:23 #11495

So what are the above brackets used for. I am not familiar with the 2003 standard. The program I am trying to compile was listed as a Fortran 95 example.

28 Jan 2013 10:31 #11496

The [ ] brackets are NOT part of Fortran 95 so your online source is wrong.

For example, you can set the first 10 elements of an array using:

real :: a(10)
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

or, another way is

real :: a(10)
a = [(i, i=1,10)]

In Fortran 95 you must use the combination (/ for [ and the combination /) for ] so the above examples become

real :: a(10)
a = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)

and

real :: a(10)
a = (/(i, i=1,10)/)
Please login to reply.