0

If I know the rank and/or size of an array being passed to a function or subroutine, is there any reason to use an assumed-shape or assumed-size array? For example, if I can replace

function f(a,m,n)
   real,dimension(*),intent(inout) :: a
   ! ...
end function

with

function f(a,m,n)
    real,dimension(m,n),intent(inout) :: a
    ! ...
end function

is there any reason (in Fortran 90 or later) to not do so?

Patrick Sanan
  • 2,375
  • 1
  • 23
  • 25
  • Your code example has an assumed-size array argument. The title and text mention assumed-shape also. Assumed shape and assumed size are _massively_ different in terms of implications. Are you truly interested in comparing explicit-shape with assumed-shape? – francescalus Sep 02 '16 at 09:47
  • Thanks for pointing that out. I am indeed interested in comparing assumed-size with explicit-shape (if that's what you mean by the second example above). I will update the title. – Patrick Sanan Sep 04 '16 at 15:21

1 Answers1

5

Too long for a comment, not much of an answer ...

This

function f(a,m,n)
    real,dimension(m,n),intent(inout) :: a
    ! ...
end function

does not make a an assumed-shape array, it has explicit shape (m,n). These days I write

function f(a)
    real,dimension(:,:),intent(inout) :: a
    ! ...
end function

In this version a is definitely assumed-shape. On the (increasingly) rare occasions I need the size or shape of an array inside a procedure I get it by writing shape(a) or suchlike.

Finally, to answer OP's question, refer to Assumed size arrays: Colon vs. asterisk - DIMENSION(:) arr vs. arr(*)

Community
  • 1
  • 1
High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
  • Pretty much when you start to make functions f2, f3, and f4 and they are only differing by the size of M and N, then you head towards @High Performance Mark example #2. Mark mentioned SHAPE and UBOUND and LBOUND become useful. – Holmz Sep 03 '16 at 10:22
  • Sorry for the confusion - I wrote assumed-shape when I meant assumed-size. – Patrick Sanan Sep 04 '16 at 15:23