FORTRAN Programming Error: Incomparable ranks 0 at and 1 in assignment.

Click For Summary

Discussion Overview

The discussion revolves around a FORTRAN programming error related to variable assignments, specifically the error message "Incomparable ranks 0 at and 1 in assignment." Participants are examining the code provided by the original poster to identify the source of the error and suggest potential fixes.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant points out that the variables newsum and oldsum are declared as allocatable arrays but are used as scalar variables, which may be causing the error.
  • Another participant agrees and suggests that the user should declare newsum and oldsum as scalars instead of arrays, noting that they are being used as scalars in the code.
  • The original poster mentions that they attempted to change newsum and oldsum to scalars but the issue persists, indicating a potential misunderstanding or further error in the code.
  • Another participant requests clarification on the changes made to newsum and oldsum, emphasizing the need to see the updated code to provide better assistance.

Areas of Agreement / Disagreement

Participants generally agree on the initial diagnosis regarding the variable declarations, but the original poster's continued issues suggest that there may be unresolved aspects of the problem. The discussion remains open without a consensus on a definitive solution.

Contextual Notes

There is uncertainty regarding the specific changes made to the code after the initial suggestions, which may affect the troubleshooting process. The original poster's implementation of the suggested changes has not been clarified.

The_shadow
Messages
18
Reaction score
0
Hi guys having a problem with my code, FORTRAN keeps stating:

lambda(k+1)=(newsum/oldsum)

Error: Incomparable ranks 0 at and 1 in assignment. The code is below:

subroutine powerit(a,b,c,E,n)
implicit none


real, intent(in) :: E
real, intent(inout) :: a(:),b(:),c(:)
!real, intent(out) :: x(:)
real,allocatable :: Phi(:),lambda(:),newsum(:),oldsum(:),d(:),x(:)
real :: phi_0,lambda_0
integer k, I, n

I = 100
phi_0 = 1
lambda_0 = 1

phi(1) = phi_0
lambda(1) = lambda_0

oldsum = phi_0
allocate(lambda(I),phi(I))
Do k = 1, I-1
d(k) = lambda(k)*E*Phi(k)
call tridiag(a,b,c,d,n,x)
Phi(k+1)=x(k)
newsum = sum(Phi)
lambda(k+1) = (newsum/oldsum)
print*, k, lambda(k+1), Phi(k+1)
oldsum = newsum

End do
deallocate(lambda)


end subroutine powerit

end module powermethord

Any ideas? Cheers guys!
 
Technology news on Phys.org
You declared newsum and oldsum to be allocatable arrays, but you seem to be using them as scalar variables.

If you divide an array by an array (element by element) you get an array (in your code, of rank 1). You can't assign that to a scalar (of rank 0). That's what the error message says.
 
Yeah...what AlephZero said.

What you need to do is stop declaring newsum and oldsum as if they were arrays and declare them as scalars...that is all they are, that is how you are using them and you never allocated them either...so...
 
thanks guys, but I have played around with making newsum and oldsum scalars - however its still not working!? Any ideas. Thanks guys!
 
What's the problem, now? Please indicate.

Also, please include your code again...I want to see how you turned newsum from array to scalar...hopefully you did not just removed the parenthesis and left the variable name in the same place!

When including code, surround it with the
Code:
tags.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
2K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K