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

AI Thread Summary
The discussion centers around a FORTRAN coding issue where an error occurs during the assignment of a variable, specifically "Incomparable ranks 0 at and 1 in assignment." The user is attempting to assign a value to lambda(k+1) using the expression (newsum/oldsum), but both newsum and oldsum were initially declared as allocatable arrays. The key points of advice highlight that these variables should be declared as scalars instead, as they are being used in a scalar context. Despite attempts to correct this by changing their declarations, the user continues to face issues and seeks further assistance. The conversation emphasizes the importance of ensuring variable types match their intended use in the code to avoid rank-related errors.
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Replies
4
Views
2K
Replies
4
Views
2K
Replies
12
Views
2K
Replies
7
Views
3K
Replies
12
Views
3K
Replies
8
Views
2K
Back
Top