|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
CompuPayMike
Joined: 10 Mar 2009 Posts: 23 Location: USA
|
Posted: Fri Jan 25, 2013 10:13 pm Post subject: Statement that does not compile |
|
|
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 |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Jan 25, 2013 10:57 pm Post subject: |
|
|
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:
Code: |
program main
integer i
real A(2,2)
A = reshape((/(real(i), i = 1, size(A))/), shape(A))
end
|
_________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
CompuPayMike
Joined: 10 Mar 2009 Posts: 23 Location: USA
|
Posted: Mon Jan 28, 2013 3:23 pm Post subject: [] |
|
|
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. |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Jan 28, 2013 11:31 pm Post subject: |
|
|
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:
Code: |
real :: a(10)
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
or, another way is
Code: |
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
Code: |
real :: a(10)
a = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)
|
and
Code: |
real :: a(10)
a = (/(i, i=1,10)/)
|
_________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|