fortran, passing allocatable arrays to a subroutine with right bounds

后端 未结 1 409
轻奢々
轻奢々 2020-12-30 14:29

I need in a program to pass some allocatable arrays to subroutines, and i need to know if the way I do it are in the standard or not.

If you know where I can search

相关标签:
1条回答
  • 2020-12-30 14:49

    The first version passes the array slice to the subroutine. Note that boundary information are not passed along in this way, arrays are assumed to start at 1 and go to size(array).

    The second way is just like the first one, but you manually set the lower boundary to 0, that's why printing v3(1:3) gives you the values with an offset of 1.

    The third way passes all array information to the subroutine (including boundaries), hence the "correct" indexing. Passing allocatable arrays was introduced with Fortran 2003.

    Apart from the fact that you have an aliasing issue (passing the same variable to three different dummy arguments), all three versions are legal.

    You can find all documents of the standards here.

    Especially, take a look at the Fortran 2003 Standard, Ch. 5.1.2.5 DIMENSION attribute to see the differences between assumed shape and deferred shape arrays in dummy arguments.

    0 讨论(0)
提交回复
热议问题