Troubleshooting Fortran 90 Errors: Rank Mismatch in Arguments | RFK.f90

In summary: The specific error message is saying that the first argument is the problem, and it is expecting a scalar but getting an array. So that's why I think it's the first argument that's the problem. But I do think there are other issues with the code as well, not just with the first argument of the second and subsequent calls to ODEfunction.
  • #1
Jonathan1234
4
0
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:
RFK.f90:65.20:

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

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

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

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

Attachments

  • a.out.zip
    30 KB · Views: 235
Technology news on Phys.org
  • #2
Jonathan1234 said:
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:
RFK.f90:65.20:

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

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

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

k6 = ODEfunction(time+c13*h, y(1:neqn)+&
1
Error: Rank mismatch in argument 't' at (1) (scalar and rank-1)
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.
 
  • #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.
 
  • #4
gsal said:
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
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.
gsal said:
..either it expects a scalar and you are passing an array or the other way around. Something like that.
 
  • #5
Mark44:
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.
 
  • #6
gsal said:
Mark44:
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.
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.
 
  • #7
The problem is this in RKF.f90:
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)".
 
  • #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.
 
  • #9
Mark44 said:
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.

I will try that, however, i am confused on why the error is giving me t
DrClaude said:
The problem is this in RKF.f90:
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)".
OMG! This worked! Thank you I feel really foolish that completely went over my head
 
  • #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?
 
  • #11
gsal said:
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.
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.
 
  • #12
Jonathan1234 said:
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?
Here's the code from ODEfunction.f90.
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.
 

What is Fortran 90?

Fortran 90 is a programming language used for scientific and engineering applications. It is an updated version of the previous Fortran programming language, with added features and improvements.

Why am I getting a Fortran 90 error?

There could be several reasons for getting a Fortran 90 error, such as syntax errors, missing or incorrect inputs, or compatibility issues with the compiler or operating system. It is important to carefully check your code and consult the language's documentation for potential solutions.

How do I fix a Fortran 90 error?

To fix a Fortran 90 error, you will need to identify the specific cause of the error. This could involve debugging your code, checking for compatibility issues, or making changes to your compiler settings. It is also helpful to consult online resources or seek assistance from other Fortran programmers.

Where can I find resources to learn Fortran 90?

There are various online resources available to learn Fortran 90, including tutorials, documentation, and forums where you can ask questions and seek help from experienced programmers. Many universities and institutions also offer courses or workshops on Fortran programming.

Is Fortran 90 still relevant in modern programming?

Yes, Fortran 90 is still widely used in scientific and engineering fields due to its efficient performance and specialized features. It continues to be updated and improved, with newer versions like Fortran 95 and Fortran 2003 being released. It is also often used in combination with other languages for complex applications.

Similar threads

  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
7
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Back
Top