所以我被Fortran再次感到困惑。去搞清楚。无论如何,我试图编写一个非常简单的例程,条带值从数组的末尾开始。复杂的一切工作正常,除了我想编写子程序,使得我不必将输入数组的下限传递给它。这是子程序:
subroutine Strip(list,lstart, index)
implicit none
integer :: i, index, isize, tsize, lstart, istart
real, dimension(:), allocatable, intent(inout) :: list
real, dimension(:), allocatable :: tlist
isize = size(list)
tsize = index-1
print *, 'index', index
print *, 'isize', isize
print*, 'lbound', INT(lbound(list))
print*, 'tsize', tsize
istart = lbound(list) !<---- This lines throws the error
!These are commented out because everything below here works
!allocate(tlist(lstart:tsize))
!tlist = list(lstart:index-1)
!deallocate(list)
!call move_alloc(tlist,list)
end subroutine Strip
现在我将输入列表的下限传递给子程序(lstart),但我不想这样做。无论如何,这段代码没有编译,编译器抛出错误6366: The shapes of the array expressions do not conform [ISTART]
我不知道如何解决这个问题。有什么建议?
答案 0 :(得分:0)
Lbound()
返回一个数组!阅读https://gcc.gnu.org/onlinedocs/gfortran/LBOUND.html
它返回一个数组,其数组与数组的排名(&#34;维度&#34; 1D,2D,...)一样多。
要获取单个数字,对于特定维度,请使用可选参数DIM。
istart = lbound(list, 1)