2017-07-25 38 views
0

所以我再次被Fortran困惑。去搞清楚。无论如何,我正在试图写一个非常简单的例程,这些条带在数组的末尾。一切复杂工作正常,除了我想写的子例程,我不必将输入数组的下限传递给它。下面是子程序:Fortran - 绑定抛出错误6366“数组表达式的形状不符合”

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()返回数组!阅读Fortran手册(RTFM)https://gcc.gnu.org/onlinedocs/gfortran/LBOUND.html

它返回一个数组,其中包含与数组的rank(“dimension”1D,2D,...)一样多的元素。

要获取单个数字,对于特定维度,请使用可选参数DIM。

istart = lbound(list, 1) 
+0

我从字面上读了一个教程,说它返回一个整数。跆拳道。感谢您的帮助,如果这不能解决问题,我会尽快回复您。 – GeneralPancake

+0

好了,以便解决这个问题,但现在使用“deallocate(list)”和“move_alloc(tlist,list)”会抛出访问冲突错误。我也不知道如何解决这个问题。你能帮我吗? – GeneralPancake

+0

tsize和index-1的值是否相同?你不需要在这里进行分配或取消分配 - 对tlist的分配将执行分配(你正在使用ifort,所以使用版本17或添加-standard-semantics)。同样,move_alloc将取消分配列表。我的猜测是你在某处损坏了内存。将-CB添加到编译中可能会有所帮助,但是ifort在运行时尚未进行形状检查。 –

相关问题