Rank mismatch in argument (Fortran 90)

  • Fortran
  • Thread starter MelihAltunan
  • Start date
  • Tags
    Argument rank
In summary, the problem is that the dimensions of the argument 'rho' are not matching. This causes a warning message to be issued and the program to crash.
  • #1
MelihAltunan
8
0
Hello everyone, i am dealing with the code which can help me to solve fluid dynamics problems with using LBM methods. Anyways, since i am beginner on Fortran i couldn't solve the rank mismatch error, i think it is easy one but i just can't fix it, i am waiting for your help. Here is the problem part;

subroutine collesion(u,v,f,feq,rho,omega,w,cx,cy,n,m,tm,tminv,stmiv)
real f(0:8,0:n,0:m)
real feq(0:8,0:n,0:m),rho(0:n,0:m)
real w(0:8), cx(0:8),cy(0:8)
real u(0:n,0:m), v(0:n,0:m)
real tm(0:8,0:8),tminv(0:8,0:8),stmiv(0:8,0:8)
real fmom(0:8,0:n,0:m),fmeq(0:8,0:n,0:m)
!calculate equilibrium moments
do i=0,n
do j=0,m
fmeq(0,i,j)=rho(i,j)
fmeq(1,i,j)=rho(i,j)*(-2.0+3.0*rho(i,j)*(u(i,j)*u(i,j)+v(i,j)*v(i,j)))
fmeq(2,i,j)=rho(i,j)*(1.0-3.0*rho(i,j)*(u(i,j)*u(i,j)+v(i,j)*v(i,j)))
fmeq(3,i,j)=rho(i,j)*u(i,j)
fmeq(4,i,j)=-rho(i,j)*u(i,j)
fmeq(5,i,j)=rho(i,j)*v(i,j)
fmeq(6,i,j)=-rho(i,j)*v(i,j)
fmeq(7,i,j)=rho(i,j)*(u(i,j)*u(i,j)-v(i,j)*v(i,j))
fmeq(8,i,j)=rho(i,j)*u(i,j)*v(i,j)
end do
end do

the error is Warning: Rank mismatch in argument 'rho' at (1) (rank-2 and scalar)

i guess it's because fmeq and rho have different ranks but how i can write in a proper way?

Thank you for now.
 
Technology news on Phys.org
  • #2
I would check elsewhere in the program where the subroutine collesion is called. It is possible that the variable 'rho' has not been declared with the proper dimensions in other parts of the program. The error message suggests that there is a mismatch in the dimensions of the arguments between calling the routine collesion and the dimensions of rho in the subroutine itself.
 
  • #3
i checked the code rho has same dimensions everywhere and also i am receiving 'segmentation fault-invalid memory reference' error on simply fortran then it shows the line 11 above (fmeq(0,i,j)=rho(i,j)). And when i try to run on microsoft developer studio it says 'wrong number of arguments to procedure COLLESION invoked from main: 13 found, 14 expected' without showing any lines. Do you have any idea about that? thank you for your help.
 
  • #4
Asking for help like this without posting the entire program can lead to a lot of speculation and a waste of time.

Either post the entire program or a minimal one that still shows the problem...then, again, when one does the step of going to a minimal program often the problem is found.
 
  • #5
By the way, I noticed that omega, n, and m do not seem to have been declared in your subroutine...this leads me to believe that you do NOT have an IMPLICIT NONE statement in your program...which opens the door for a lot of things.
 
  • #6
i tried with IMPLICIT NONE but it had same problem again. Considering what you said, i added the code as an attachment. So, the best way is if you run the code with your own compiler, you will see the what is an error. I would be pleased if you can check the code that i uploaded. Thanks.
 

Attachments

  • liddrivenre=100(MRT).zip
    1.9 KB · Views: 211
  • #7
No need to compile...the problem is very clear, just compare the signature of the subroutine as declared (order and quantity of arguments) and see how you are calling it:

Code:
call collesion(u,v,feq,rho,omega,w,cx,cy,n,m,tm,tminv,stmiv)
subroutine collesion(u,v,f,feq,rho,omega,w,cx,cy,n,m,tm,tminv,stmiv)

Notice anything?
 
  • #8
yea, i noticed :), it is working now, thanks a lot.
 

1. What is a "Rank mismatch in argument" in Fortran 90?

A rank mismatch in argument in Fortran 90 refers to an error that occurs when the dimension or shape of an array or argument does not match the expected dimension or shape in a subroutine or function call. This can happen when the dimensions of the array or argument are not defined correctly or when the wrong array or argument is passed in the call.

2. How does Fortran 90 handle rank mismatch errors?

Fortran 90 will flag a rank mismatch error as a compilation error, meaning the program will not be able to run until the error is corrected. The compiler will provide a specific error message indicating which subroutine or function call is causing the mismatch. It is important to carefully check the dimensions and shapes of all arrays and arguments to ensure they match correctly.

3. What are some common causes of rank mismatch errors in Fortran 90?

The most common cause of rank mismatch errors in Fortran 90 is a simple mistake in defining the dimensions of an array or argument. This can happen when using the wrong variable or when the dimension is not specified correctly. Another common cause is passing in the wrong array or argument in a subroutine or function call. It is important to double check all declarations and calls to avoid these errors.

4. How can I prevent rank mismatch errors in my Fortran 90 code?

To prevent rank mismatch errors, it is important to carefully define the dimensions and shapes of all arrays and arguments in your code. This includes checking for any typos or incorrect variable names. It is also helpful to use comments in your code to remind yourself of the intended dimensions and shapes of each array. Additionally, regularly testing and debugging your code can catch any potential rank mismatch errors before they become a problem.

5. Are there any tools or resources available to help with identifying and fixing rank mismatch errors in Fortran 90?

Yes, there are various debugging tools and resources available to assist with identifying and fixing rank mismatch errors in Fortran 90. Most Fortran compilers will provide error messages that can help pinpoint the source of the error. Additionally, there are online forums and communities where you can ask for help and advice from experienced Fortran programmers. There are also debugging tools specifically designed for Fortran, such as the GNU Debugger, which can help with identifying and fixing these types of errors.

Similar threads

  • Programming and Computer Science
Replies
4
Views
602
  • Programming and Computer Science
Replies
8
Views
5K
  • Programming and Computer Science
Replies
1
Views
938
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
1
Views
6K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top