2017-07-25 859 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在運行時尚未進行形狀檢查。 –