我正在使用標誌f
進行一些錯誤檢查。當我想執行另一個檢查時,Fortran(或者也許gfortran)不會讓我重新分配它的價值。「無法分配給命名常量」(重新分配變量)
integer, dimension(:,:), allocatable :: A
integer :: f, n
write (*, *) "Give an integer n > 0. n = "
read (*, IOSTAT=f) n
do while(f /= 0)
print *, "Error with input. Please try again."
read (*, IOSTAT=f) n
end do
write (*, "(a, i5)") "You have entered n = ", n
allocate(A(n), STAT=f)
if (f /= 0)
print *, "Error: not enough memory for A."
end if
注意:我認爲複製粘貼可能會弄亂我的間距。
f
已被聲明爲整數(而不是整數參數):integer :: f
。
我非常喜歡Fortran的初學者,所以很可能我犯了一個不可思議的錯誤!
當我說'allocate(A(n))'時有錯誤嗎?它應該是「分配(A(n,n))」嗎? – jamesh625
這個奇怪的錯誤消息是gfortran中的一個已知錯誤:https://gcc.gnu.org/bugzilla/show_bug.cgi?id = 34325 – agentp