keeping array limits in fortran during subroutine call

后端 未结 3 490
执笔经年
执笔经年 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:21

    The type of dummy argument that you are are using in the subroutine, with the dimension specified with a colon, is called "assumed shape". This name is the clue -- Fortran passes only the shape and not the lower and upper bounds. The lower bound is assumed to be one unless you override it as shown in the answer by kemiisto. If the lower bound is not fixed, you can pass an argument to use as the lower bound.

    Later addition: a code example if the lower dimension isn't known at compile time:

    subroutine example (low, array)
       integer, intent (in) :: low
       real, dimension (low:), intent (out) :: array
    

提交回复
热议问题