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

In summary, the conversation is about a problem with a code written in FORTRAN. The error message states that there is an incomparable rank in an assignment. The code involves a subroutine called powerit, which takes in some parameters and allocates arrays for phi, lambda, newsum, oldsum, d, and x. The code also includes a loop and a call to a function called tridiag. The issue seems to be related to the use of newsum and oldsum as arrays instead of scalars. The conversation ends with a request for help and a reminder to use the tags when including code.
  • #1
The_shadow
19
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
  • #2
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.
 
  • #3
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...
 
  • #4
thanks guys, but I have played around with making newsum and oldsum scalars - however its still not working!? Any ideas. Thanks guys!
 
  • #5
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.
 

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

What is a FORTRAN Programming Error?

A FORTRAN Programming Error is an error that occurs while writing code in the FORTRAN programming language. It means that there is an issue with the code that is preventing it from running correctly.

What does "Incomparable ranks 0 at and 1 in assignment" mean?

"Incomparable ranks 0 at and 1 in assignment" is a specific error message that can occur in FORTRAN. It means that there is an issue with comparing two values in the code, specifically at ranks 0 and 1, which could be arrays or data types.

How can I fix this error?

To fix this error, you will need to carefully review your code and identify where the issue is occurring. It could be due to a typo or a missing piece of code. Once you have identified the problem, you can make the necessary changes to ensure that the ranks 0 and 1 can be compared properly.

Why is this error occurring?

This error is occurring because there is an issue with comparing two values in the code. It could be a simple mistake or a more complex issue with the logic of the code. Understanding the specific cause of the error will help in resolving it.

Can I prevent this error from happening in the future?

Yes, you can prevent this error from happening in the future by carefully reviewing your code before running it and ensuring that all values are properly compared. It may also be helpful to use debugging tools and techniques to catch and fix errors before they occur.

Similar threads

  • Programming and Computer Science
Replies
4
Views
656
  • Programming and Computer Science
Replies
1
Views
950
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
956
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
26
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top