View previous topic :: View next topic |
Author |
Message |
acp693
Joined: 04 Sep 2006 Posts: 56
|
Posted: Wed Oct 31, 2007 12:09 pm Post subject: strange behaviour of real? |
|
|
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 |
|
|
acp693
Joined: 04 Sep 2006 Posts: 56
|
Posted: Wed Oct 31, 2007 2:23 pm Post subject: |
|
|
I just checked with gfortran, this also gives the correct result.
Any ideas anyone? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Thu Nov 01, 2007 9:17 am Post subject: |
|
|
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 |
|
|
acp693
Joined: 04 Sep 2006 Posts: 56
|
Posted: Thu Nov 01, 2007 9:47 am Post subject: |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Thu Nov 01, 2007 1:36 pm Post subject: |
|
|
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 |
|
|
acp693
Joined: 04 Sep 2006 Posts: 56
|
Posted: Thu Nov 01, 2007 2:02 pm Post subject: |
|
|
Thanks, Yes the workaround is simple, but it would be nice if it worked inline without copying to another variable first. |
|
Back to top |
|
|
|