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

Fortran 90 Error Please help

  1. Apr 6, 2015 #1
    Hey guys, I'm pretty new and desperate. I been trying to compile this program for a while and keep jumping from error to error.
    Currently I have the following error:
    Error: Rank mismatch in argument 't' at (1) (scalar and rank-1)
    I have checked that my arrays are correctly. I have checked that all my arguments are correct, also, all my # of arguments during calls are correct. I don't know where else to go and check. Any suggestions?

    The section of my program is here:
    k1 = ODEfunction(time,y,neqn)
    k2 = ODEfunction(time+c1*h, y(1:neqn)+k1*c1*h, neqn)
    k3 = ODEfunction(time+c2*h, y(1:neqn)+(c3*k1+c4*k2)*h, neqn)
    k4 = ODEfunction(time+c5*h, y(1:neqn)+(c6*k1-c7*k2+c8*k3)*h, neqn)
    k5 = ODEfunction(time+h, y(1:neqn)+(-c9*k1+c10*k2-c11*k3+c12*k4)*h, neqn)
    k6 = ODEfunction(time+c13*h, y(1:neqn)+&
    &(c14*k1+c15*k2+c16*k3+c17*k4+c18*k5)*h, neqn)

    the exact errors say:

    k2 = ODEfunction(time+c1*h, y(1:neqn)+k1*c1*h, neqn)
    Error: Rank mismatch in argument 't' at (1) (scalar and rank-1)

    k3 = ODEfunction(time+c2*h, y(1:neqn)+(c3*k1+c4*k2)*h, neqn)
    Error: Rank mismatch in argument 't' at (1) (scalar and rank-1)

    k4 = ODEfunction(time+c5*h, y(1:neqn)+(c6*k1-c7*k2+c8*k3)*h, neqn)
    Error: Rank mismatch in argument 't' at (1) (scalar and rank-1)

    k6 = ODEfunction(time+c13*h, y(1:neqn)+&
    Error: Rank mismatch in argument 't' at (1) (scalar and rank-1)

    Attached Files:

  2. jcsd
  3. Apr 6, 2015 #2


    Staff: Mentor

    All of your errors seem to be related. The 2nd argument of ODEfunction is apparently an array. In the first call to ODEfunction, the 2nd argument is y, and all is good. In subsequent calls to ODEfunction, your 2nd argument is a mishmash of stuff -- part array and part scalar -- and this is what the error messages are telling you.

    Are you trying to add k1 * c1 * h to each element of your array y? If so, use a DO loop to do that, and then call ODEfunction. The same advice applies to the other calls to ODEfunction that are generating error messages.
  4. Apr 7, 2015 #3
    It is difficult to tell what is going on without seeing ODEfunction and the type of its arguments as well as the types of the parameters that you are passing to it.

    From the error message, it looks like the problem is with the very first argument, time, judging by the "argument 't' " part ..either it expects a scalar and you are passing an array or the other way around. Something like that.
  5. Apr 7, 2015 #4


    Staff: Mentor

    I don't think the problem is with the first argument, although I agree that seeming how ODEfunction is defined would be helpful. The reason I don't think it's the first argument that is wrong is that the first call to ODEfunction isn't flagged with a compiler error, but the second and following calls are flagged, all of which have what I think are hinky expressions in their 3rd arguments.
  6. Apr 7, 2015 #5
    If the time argument was identical in both the first call and the others, I would agree with you; but given that they are different, it cannot be ruled out.

    By the way, let's recall that Fortran90 can handle arrays a-la-matlab so that adding scalars to arrays is not necessarily an illegal thing; it is only if the result then turns into an array while the argument only expects a scalar.
  7. Apr 7, 2015 #6


    Staff: Mentor

    Good point.

    Personally, I really dislike that business of adding a scalar to an array. I've been writing C and related code for so long that those shortcuts don't seem reasonable to me.
  8. Apr 8, 2015 #7


    User Avatar

    Staff: Mentor

    The problem is this in RKF.f90:
    Code (Fortran):

    REAL(dp),Dimension(27),PARAMETER ::  C1=1._dp/5._dp, &  !1
      &C2=3._dp/10._dp, &  !2
      &c3=3._dp/40._dp, &  !3
      &c4=9._dp/40._dp, &  !4
      &c5=3._dp/5._dp, &  !5
      &c6=3._dp/10._dp, &  !6
      &c7=9._dp/10._dp, &  !7
      &c8=6._dp/5._dp, &  !8
      &c9=11._dp/54._dp, &  !9
      &c10=5._dp/2._dp, &  !10
      &c11=70._dp/27._dp, &  !11
      &c12=35._DP/27._DP, &  !12
      &c13=7._DP/8._DP, &  !13
      &c14=1631._DP/55296._DP, &  !14
      &c15=175._DP/512._DP, &  !15
      &c16=575._DP/13824._DP, &  !16
      &c17=44275._DP/110592._DP, &  !17
      &c18=253._DP/4096._DP, &  !18
      &c19=37._DP/378._DP, &  !19
      &c20=250._DP/612._DP, &  !20
      &c21=125._DP/594._DP, &  !21
      &c22=512._DP/1771._DP, &  !22
      &c23=2825._DP/27648._DP, &  !23
      &c24=18575._DP/48384._DP, &  !24
      &c25=13525._DP/55296._DP, &  !25
      &c26=277._DP/14336._DP, &  !26
      &c27=1._DP/4._DP  !27
    You are defining 27 variables, each one an array of length 27. Remove the "Dimension(27)".
  9. Apr 8, 2015 #8
    With no mention of the zip file and its contents and being named a.out, I thought it may only contain the executable...I see, now, that it has the entire project.

    And, yes, DrClaude is right...and so am I with my correct interpretation of the error message. With the 'c' variables being declared arrays, the argument " time + c*h " produces an array, too...which is then of the wrong rank for the first argument in ODEfunction expecting just a scalar.

    So, go ahead and remove the "dimension(27)" attribute altogether.

    Also, just like you have the "double_precision" and "variable_library" modules, I would recommend creating a module with the other functions and spare yourself having to manually include all that (unnecessary) code to explicitly declare interfaces over and over...that would happen automatically if you use modules, instead.
  10. Apr 10, 2015 #9
    I will try that, however, i am confused on why the error is giving me t
    OMG! This worked! Thank you I feel really foolish that completely went over my head
  11. Apr 10, 2015 #10
    Thank you all! I been working on this program for a while and its been really stressfull for me. Every time I seem to fix an error another arises.

    So I ask you for one more, if I get the following error:
    At line 25 of file ODEfunction.f90
    'Fortran runtime error: Index '2' of dimension 1 of array 'y' above upper bound of -292737286985288951

    Those this go back to me trying to give the array a scalar instead of an array as it should or am I passing an array with the wrong dimensions?
  12. Apr 10, 2015 #11
    I apologize for not mentioning my zip file. It is the first time I post here and I had no idea it automatically gave it a name.
  13. Apr 10, 2015 #12


    Staff: Mentor

    Here's the code from ODEfunction.f90.
    Code (Fortran):

    Function ODEfunction(t,y,neqn)
    ! This function holds the system of differential equations used in the numberical
    ! solutions of ODEs for Engr 326 Lab. And this function will calculate the change
    ! in snail population and worm population in terms of time.
    ! Where,
    ! ODEfunction(1) = the snail population growth rate
    ! ODEfunction(2) = the worm population growth rate
    ! alpha, and beta= model coefficients given on the problem statement
    ! y(1) and y(2)  = snail and worm population density, respectively.
    ! t  = is time

     Use Double_Precision
     Use Variable_Library
     Implicit None
     Integer,Intent(in) :: neqn
     Real(dp),Intent(in) :: t
     Real(dp),Dimension(:),Intent(in) :: y
     Real,Dimension(neqn) :: ODEfunction
      write(*,*) "y=", y
      ODEfunction(1) = (alpha1-beta1*y(2))*y(1)
      ODEfunction(2) = (alpha2-beta2*(y(2)/y(1)))*y(2)  !! <<--- Line 25

    End Function ODEfunction[/quote]
    ODEfunction is a function -- you are using it as if it were an array. You need to have a clearer understanding of what your ODEfunction should be returning, and you need a different variable for your array.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Fortran 90 Error Please help
  1. Help with Fortran 90 (Replies: 0)