将循环参数视为非数字字符

时间:2013-11-24 05:31:46

标签: fortran mex

我是Fortran的新手,面对Do循环中的问题。我正在编写一个用于在Matlab中使用的MEX文件的Fortran代码。 我认为它对k和z的定义有问题,但我不明白为什么。也许你们有一个提示我,我做错了什么。非常感谢你!

错误消息和代码     innerloops.F     做k = 1,4     1     错误:语句标签中的非数字字符(1)     innerloops.F     做k = 1,4     1     错误:(1)处的不可分类陈述     innerloops.F     做z = 1,25
    1     错误:语句标签中的非数字字符(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

1 个答案:

答案 0 :(得分:3)

通过使用.F后缀,编译器默认假定您使用的是固定格式的源代码。在固定格式中,某些列保留用于特殊目的。这里看起来你的“do”被错误地放入了为语句标签保留的列(第1列到第5列)。您的语句必须在固定格式的fortran文件中适合第7列和第72列。这就是编译器所抱怨的。正如其他人所提到的,您的代码还包含其他需要修复的错误。

为了简单起见,您可以使用自由格式,而不是将后缀更改为.f90并将“C”注释指示符替换为“!”。