forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Statement that does not compile

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
CompuPayMike



Joined: 10 Mar 2009
Posts: 23
Location: USA

PostPosted: Fri Jan 25, 2013 10:13 pm    Post subject: Statement that does not compile Reply with quote

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
View user's profile Send private message Send e-mail
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Jan 25, 2013 10:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
CompuPayMike



Joined: 10 Mar 2009
Posts: 23
Location: USA

PostPosted: Mon Jan 28, 2013 3:23 pm    Post subject: [] Reply with quote

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
View user's profile Send private message Send e-mail
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Mon Jan 28, 2013 11:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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