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 

strange behaviour of real?

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



Joined: 04 Sep 2006
Posts: 56

PostPosted: Wed Oct 31, 2007 12:09 pm    Post subject: strange behaviour of real? Reply with quote

I am having problems with using the real function with complex arrays, when combined inline with sum function. The following produces strange output for the second print statement, but the last print statement which is exactly the same except not done inline ( the sum is first copied to another variable and then the real part taken works fine.

The code works in g95, all print statements are correct. I'm not sure if it's a program fault or a problem from my coding and that g95 is being tolerant.

Any help will be gratefully appreciated

Albert


program test

Implicit none

complex,dimension(1,3) :: csum
complex,dimension(10,3) :: c
real, dimension (10,6) :: r

call RANDOM_NUMBER(r)

! Build a complex array
c= cmplx(r(: , 1:5:2) , r(: , 2:6:2))

! sum of each column
csum(1, : ) = sum(c, dim=1)

print*, sum(c , dim=1 )
print*, real( sum(c , dim=1 ))
print*, aimag( sum(c , dim=1 ))
print*, real(csum)

end program
Back to top
View user's profile Send private message
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Wed Oct 31, 2007 2:23 pm    Post subject: Reply with quote

I just checked with gfortran, this also gives the correct result.

Any ideas anyone?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Thu Nov 01, 2007 9:17 am    Post subject: Reply with quote

I can see that

print*, real( sum(c , dim=1 ))


is not giving the right answer.

Is that what you are saying?
Back to top
View user's profile Send private message AIM Address
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Thu Nov 01, 2007 9:47 am    Post subject: Reply with quote

yes thats right, but it gives the right answer in g95 and gfortran. but I don't know if those compilers are simply being tolerant of my coding or has the silverfrost compiler got a problem?

The first print statement shows the complex result of the summing of each column.
The second print statement should show the real part,
The third the imaginary part,
The last print statement shows the real part of the summing of each column that was copied to another variable before printing the real part.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Thu Nov 01, 2007 1:36 pm    Post subject: Reply with quote

FTN95 ought to get it right.
I will put this on the list of things to check out.
In the mean time it will be necessary to use the alternative approach.
Back to top
View user's profile Send private message AIM Address
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Thu Nov 01, 2007 2:02 pm    Post subject: Reply with quote

Thanks, Yes the workaround is simple, but it would be nice if it worked inline without copying to another variable first.
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