keeping array limits in fortran during subroutine call

后端 未结 3 520
执笔经年
执笔经年 2021-01-19 00:56

I have the following program

module test
contains
   subroutine foo()
      integer, allocatable :: a(:)
      allocate(a(-5:5))
      call bar(a)
      prin         


        
3条回答
  •  半阙折子戏
    2021-01-19 01:20

    There are two common options:

    • As kemisto wrote, you pass a second argument. This was common in F77-style code. You can not use the LBOUND trick! It has to be passed as an integer.
    • You declare the argument to be a pointer, which includes the entire array descriptor. Then the bounds of the array in the subroutine are the same as in the calling scope. Of course you may lose on optimization this way.

提交回复
热议问题