Reputation: 145
I am having some issues with using multi-dimensional array in some fortran code I am writing.
Basically, I define a 2-dimensional array, which is passed to membrane
, then have to pass a 1-dimensional version of it to set
.
Case (1)
Call membrane ("Set", scv(i,:), sty)
Here is the routine that takes the 1-d array.
Subroutine membrane (tsk, scv, sty)
Implicit None
Character (Len=*), Intent (In) :: tsk
Logical, Intent (In), Optional :: scv(:,:)
Character (Len=*), Intent (In), Optional :: sty
Select Case (tsk)
Case ("Set")
Call set (tsk, scv(1,:), sty)
...
Here is my set subroutine
Subroutine set (tsk, scv, sty)
Implicit None
Character (Len=*), Intent (In) :: tsk
Logical, Intent (In), Optional :: scv(:)
Character (Len=*), Intent (In), Optional :: sty
I then get this error when I try to compile my code
sct/btun/membrane.f:185:35:
Call membrane ("Set", scv(i,:), sty)
1
Error: Rank mismatch in argument 'scv' at (1)
(rank-2 and rank-1)
Upvotes: 1
Views: 74
Reputation: 18098
You are calling the routine membrane
using a one-dimensional slice of scv
. Since that subroutine is expecting a two-dimensional array:
Logical, Intent (In), Optional :: scv(:,:)
You get the error. I am not quite sure what you are trying to achieve, but since you are accessing the first column of the array in membrane (hard-coded), I would change the dummy argument scv
to be one-dimensional in membrane
:
Subroutine membrane (tsk, scv, sty)
...
Logical, Intent (In), Optional :: scv(:)
...
Select Case (tsk)
Case ("Set")
Call set (tsk, scv(:), sty)
...
Note that that now the complete array is passed to set
.
Alternatively, pass the complete 2D array to membrane
along with the counter i
, and pass the i
-th row to set
.
Upvotes: 2
Reputation: 60008
"then have to pass a 1-dimensional version of it to set"
but the subroutine expects a 2D array because of
Logical, Intent (In), Optional :: scv(:,:)
Either fix the declaration or you must pass a 2D array.
Upvotes: 2