open(1,file='data.txt')
real h,v,a,t,f,v0,g,H0
f=0.03
t=0.1
g=9.8
H0=100
a=g
h=0
v=0
v0=sqrt(g/f)
do while(h<=H0)
v=v+a*t
a=g-f*v**2
h=h+v*t+0.5*a*t**2
if(v>v0)then
write(*,"(1x,F3.4)") v0
else
write(*,"(1x,F3.4)") v
end if
end do
end
错误如下
F:\fortran hui\Text1.for(2) : Error: A specification statement cannot appear in the executable section.
real h,v,a,t,f,v0,g,H0
--------^
Error executing df.exe.
大家帮忙看看Fortran中这个错误是什么?怎么改?
答案:2 悬赏:10
解决时间 2021-03-21 05:58
- 提问者网友:無奈小影
- 2021-03-20 18:43
最佳答案
- 二级知识专家网友:伤口狠精致
- 2021-03-20 19:58
这个错误的意思是类型声明语句不能出现在执行语句部分。
Fortran中类型声明语句在最前面。你把类型声明语句放到open那句话前面就行了。
Fortran中类型声明语句在最前面。你把类型声明语句放到open那句话前面就行了。
全部回答
- 1楼网友:陪我到地狱流浪
- 2021-03-20 21:34
正确程序如下:----------------------------
!主程序
program main
external f1,f2
double precision x,y,e,a,b,f1,f2,ex,ey
open(9,file="v(x,y).dat",status='unknown')
a=3.14/3.0
b=2.0*3.14/3.0
do i=1,n
x=0.0-2.0+i*0.05
if(x<=2.0)then
do j=1,n
y=0.0-2.0+j*0.05
call simp(a,b,f1,x,y,ex)
call simp(a,b,f2,x,y,ey)
e=dsqrt(ex**2+ey**2)
write(*,*) x,y,e
write(9,*) x,y,e
end do
end if
end do
end
!定义被积函数子程序f1(t,x,y)
function f1(t,x,y)
double precision f1,t,x,y
f1=(x-dcos(t))/dsqrt(((x-dcos(t))**2+(y-dsin(t))**2)**3) ! 此处令r=1,( / ) =1
end
!定义被积函数子程序f2(t,x,y)
function f2(t,x,y)
double precision f2,t,x,y
f2=(y-dsin(t))/dsqrt(((x-dcos(t))**2+(y-dsin(t))**2)**3) ! 此处令r=1,( / ) =1
end
!用simpson法积分求电场强度e的子程序simp
subroutine simp(a,b,f,x,y,s)
double precision a,b,x,y,f,h,s1,s2,s
integer n
n=1000
h=(b-a)/(2*n)
v=0.5*(f(a,x,y)-f(b,x,y))
do i=1,n
s1=f(a+(2*i-1)*h,x,y)
s2=f(a+2*i*h,x,y)
s=s+2*s1+s2
end do
s=(b-a)*s/(3*n)
end
错误有几点:-----------------------------------------
1. 表示注释的符号为英文感叹号!,原来误为中文感叹号!。
2. 主程序中没有将变量ex,ey定义为双精度,故使用函数dsqrt会出错。
3. 子函数f2中,等式左边将f2误为f1。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯