0
我是Fortran的新手,面臨Do循環內的問題。我正在爲Matlab中的MEX文件編程一個Fortran代碼。 我認爲它有k和z的定義問題,但我不明白爲什麼。也許你們對我的暗示是我做錯了什麼。非常感謝你!將循環參數視爲非數字字符
錯誤消息和代碼 innerloops.F 做k = 1時,4
錯誤:在聲明標籤非數字字符在(1) innerloops.F 做k = 1時,4
1個 錯誤:在(1) innerloops.F 不可分類的聲明做Z = 1,25
錯誤:非數字字符在聲明標籤在(1) innerloops.F 做Z = 1,25
錯誤:在(1)
C Computational routine
subroutine innerloops(J,c1,c2,c3,c4,n1,n2,n3,n4,y,m,n)
mwSize m, n
integer k, z
real*8 J(m,n), y(4,1), c1, c2, c3, c4, n1, n2, n3, n4
real*8 QuadRuleX(25,2)
real*8 QuadRuleW(25,1)
real*8 X(5,1), r, t
real*8 P, c_h, n_h
integer h = 10
C Gaussian Points
X(1) = -.906179
X(2) = -.538469
X(3) = 0
X(4) = .538469
X(5) = .906179
C Corresponding QuadRule points
QuadRuleX(1,1) = X(1)
QuadRuleX(1,2) = X(1)
C .... (snipped it here for readability)
C Corresponding weights
QuadRuleW(1) = Y(1)*Y(1)
QuadRuleW(2) = Y(2)*Y(1)
C .... (snipped it here for readability)
do k = 1, 4
do z = 1, 25
r = QuadRuleX(z,1)
t = QuadRuleX(z,2)
P = shape(k,r,t)
c_h = c1*shape(k,r,t)
n_h = n1*shape(k,r,t)
y(k,1) = (P*((((h-1)*c_h)/(h-1)*c_h+1))*n_h*(2-n_h)-n_h)
continue
continue
return
end do
end subroutine innerloops
C defining the shape functions
Function shape(q,c,d)
implicit none
real q,c,d,P
if (q == 1) then
P = 1/4*(c-1)*(d-1)
else if (q == 2) then
P = -1/4*(c+1)*(d-1)
else if (q == 3) then
P = 1/4*(c+1)*(d+1)
else if (q == 4) then
P = -1/4*(c-1)*(d+1)
endif
return
end Function shape
看起來你錯過了「do k = 1,4」的「end do」。 –
是的。你可能希望'end do'而不是每個'continue'語句。然後在'return'語句後刪除'end do' - 它是不可訪問的。縮進將使您的代碼更具可讀性。 –
不是你錯誤的原因,但知道整數除法1/4產生零。最好使那個1./4。 .. – agentp