Type/rank mismatch in argument

  • Thread starter Giammy85
  • Start date
  • Tags
    Argument
In summary, the conversation is discussing an issue with allocating arrays and passing them to a function in Fortran. The user may have encountered a type/rank mismatch error and is trying to figure out what they are doing wrong. They suggest that the subroutine may also need to declare the variables as real allocatable instead of double. The issue is eventually resolved by declaring all variables as double in the main program.
  • #1
Giammy85
19
0
Hi,

I'm allocating the dimension of some arrays once I have calculated steps, then I send the allocated arrays to a function but I have the error Type/rank mismatch in argument 'a'.

What am I doing wrong?

Cheers


integer i, steps, noutput, savestep

double integrationtime, outputstep, timestep, deltat, ain, ein

real, dimension(:), allocatable :: a, e, time

steps=int(integrationtime/timestep)



allocate(time(steps), a(steps), e(steps))
time(0)=0.0d0
a(0)=ain*1.49597870691d11
e(0)=ein



call calc (steps, a, e, time)



stop



contains



subroutine calc (steps, a, e, time)

integer i, steps

double precision time(steps), a(steps), e(steps)


do i=1, steps
time(i)=


a(i)=...

e(i)=...


end subroutine calc
 
Technology news on Phys.org
  • #2
I'm not that familiar with modern fortran, but would the subroutine calc also need to delcare a , e, and time as real allocatable (versus double)?
 
  • #3
Unfortunately by doing so I have ever more error messages:
In file tidalevolution.f90:84

real, dimension(:), allocatable :: a, e, time
1
Error: ALLOCATABLE attribute conflicts with DUMMY attribute at (1)
In file tidalevolution.f90:86

allocate(time(steps), a(steps), e(steps))
1
Error: Syntax error in ALLOCATE statement at (1)
 
  • #4
OK, then could it just be a problem with the parameters from the main program being decleared as real while the subroutine parameters are declared as double?
 
  • #5
Yes, solved
 

What is a "Type/rank mismatch in argument" error?

A "Type/rank mismatch in argument" error is a type of programming error that occurs when a function is called with an argument of a different type or rank (dimensionality) than what the function expects. This can happen in languages such as C or Fortran, where the types and ranks of variables must match exactly for the code to run correctly.

How does a "Type/rank mismatch in argument" error happen?

A "Type/rank mismatch in argument" error can happen when the programmer inadvertently passes the wrong type of variable or an array of the wrong rank to a function. It can also happen if the function is expecting a pointer to a certain type, but is instead passed a pointer to a different type.

What are some common causes of "Type/rank mismatch in argument" errors?

Some common causes of "Type/rank mismatch in argument" errors include using the wrong type of variable or array in a function call, passing a pointer to a different type of variable than the function expects, or using incorrect syntax when calling a function.

How can "Type/rank mismatch in argument" errors be prevented?

To prevent "Type/rank mismatch in argument" errors, it is important for programmers to carefully check the types and ranks of variables and arrays before passing them to a function. It is also helpful to use good coding practices such as using descriptive variable names and proper commenting to avoid confusion.

How are "Type/rank mismatch in argument" errors typically debugged?

"Type/rank mismatch in argument" errors can be debugged by carefully reviewing the code and checking for any mismatches between the types and ranks of variables and function arguments. Debugging tools such as debuggers or print statements can also be helpful in identifying the source of the error.

Similar threads

  • Programming and Computer Science
Replies
4
Views
464
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
11
Views
3K
  • Programming and Computer Science
Replies
1
Views
6K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
11
Views
14K
  • Programming and Computer Science
Replies
18
Views
6K
  • Programming and Computer Science
Replies
5
Views
5K
Back
Top