Silverfrost Forums

Welcome to our forums

strange behaviour of real?

31 Oct 2007 11:09 #2393

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

31 Oct 2007 1:23 #2395

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

Any ideas anyone?

1 Nov 2007 8:17 #2396

I can see that

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

is not giving the right answer.

Is that what you are saying?

1 Nov 2007 8:47 #2397

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.

1 Nov 2007 12:36 #2399

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.

1 Nov 2007 1:02 #2400

Thanks, Yes the workaround is simple, but it would be nice if it worked inline without copying to another variable first.

Please login to reply.