Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Apr 4, 2012 #1
    Hi guys having a problem with my code, FORTRAN keeps stating:


    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
    Do k = 1, I-1
    d(k) = lambda(k)*E*Phi(k)
    call tridiag(a,b,c,d,n,x)
    newsum = sum(Phi)
    lambda(k+1) = (newsum/oldsum)
    print*, k, lambda(k+1), Phi(k+1)
    oldsum = newsum

    End do

    end subroutine powerit

    end module powermethord

    Any ideas? Cheers guys!
  2. jcsd
  3. Apr 4, 2012 #2


    User Avatar
    Science Advisor
    Homework Helper

    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.
  4. Apr 4, 2012 #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...
  5. Apr 13, 2012 #4
    thanks guys, but I have played around with making newsum and oldsum scalars - however its still not working!? Any ideas. Thanks guys!
  6. Apr 13, 2012 #5
    What's the problem, now? Please indicate.

    Also, please include your code again...I wanna 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 (Text):
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook