-4
我不熟悉Fortran中的錯誤。你能解釋一下這些錯誤是什麼?如何修復Fortran代碼中的錯誤
int.f90(18): error #5082: Syntax error, found IDENTIFIER 'K' when expecting one of: (% : . = =>
do k=0.0 to m
---^
int.f90(19): error #5082: Syntax error, found IDENTIFIER 'Q' when expecting one of: (% : . = =>
do q=1 to m-1
----^
int.f90(20): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of:) ,
f1=1/(2*pi)*(sqrt((k**2)+(Q**2)-(2*k*cos(t)))
----------------------------------------------^
int.f90(24): error #5082: Syntax error, found IDENTIFIER 'I' when expecting one of: (% : . = =>
do i=1 to m-1
----^
int.f90(4): error #6406: Conflicting attributes or multiple declaration of name. [INT]
function int(f,a,b,int,m)
-------------------^
int.f90(9): error #6418: This name has already been assigned a data type. [M]
integer:: i,m
------------^
int.f90(10): error #6557: An =initialization-expr is missing; an initialization expression is required when using the PARAMETER attribute. [PI]
real,parameter:: pi,pi=3.14
-----------------^
int.f90(10): error #6418: This name has already been assigned a data type. [PI]
real,parameter:: pi,pi=3.14
--------------------^
int.f90(11): error #6557: An =initialization-expr is missing; an initialization expression is required when using the PARAMETER attribute. [EPS]
real,parameter:: eps,eps=1.89
-----------------^
int.f90(11): error #6418: This name has already been assigned a data type. [EPS]
real,parameter:: eps,eps=1.89
---------------------^
int.f90(12): error #6557: An =initialization-expr is missing; an initialization expression is required when using the PARAMETER attribute. [E]
real,parameter:: e,e=1.602*((10)**(-19))
-----------------^
int.f90(12): error #6418: This name has already been assigned a data type. [E]
real,parameter:: e,e=1.602*((10)**(-19))
-------------------^
int.f90(21): error #6099: An ENDDO statement occurred without a corresponding DO or DO WHILE statement.
end do
-^
int.f90(23): error #6099: An ENDDO statement occurred without a corresponding DO or DO WHILE statement.
end do
-^
int.f90(26): error #6410: This name has not been declared as an array or a function. [F2]
s=2*f2(t)+4*f2(t+h)
-----^
int.f90(27): error #6099: An ENDDO statement occurred without a corresponding DO or DO WHILE statement.
end do
-^
,這是我的代碼:
function int(f,a,b,int,m)
implicite none
double precision f1,f2,a,b,m,int,s
double precision h,t
integer:: k,q
integer:: i,m
real,parameter:: pi,pi=3.14
real,parameter:: eps,eps=1.89
real,parameter:: e,e=1.602*((10)**(-19))
a=0.0
b=pi
m=150
s=0.0
h=(b-a)/m
do k=0.0 to m
do q=1 to m-1
f1=1/(2*pi)*(sqrt((k**2)+(Q**2)-(2*k*cos(t)))
end do
f2=((2*pi*(e**2))/eps)*f
end do
do i=1 to m-1
t=a+(i*h)
s=2*f2(t)+4*f2(t+h)
end do
int=(h/3)*(s+f2(a)+f2(b)+4*f2(a+h))
print*,int
return
end function int
一般而言,如果您在發佈代碼的同時發佈錯誤信息,則可以獲得更好的幫助。有時候真正的錯誤是在編譯器選擇的那一行之前。在這種情況下,我在你的循環中看到這個「to」,這似乎是可疑的。我不熟悉那種語法。第一個應該是'do k = 0,m',除非你使用了一些我沒有看到的新語法。 (另外,'k'可能是整數,所以賦值爲'0.0'要麼是混淆,要麼是錯誤。) – Brick
請發佈源代碼。如果它太大,請編寫一個新的,更短的程序來重現您的錯誤。看到這個:http://stackoverflow.com/help/mcve – solalito
我會幫助,但是當你甚至不知道如何聲明像'do'循環這樣的最基本的語句時,給你提供解決方案似乎是不對的。我建議你先在網上閱讀一些教程。 – solalito