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

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 5K views
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!
 
Physics 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.