fortran程序,subroutine solvereal::i,x,y,mreal::h(i),d(i),a(i),dy(i)h(i)=(1+2*(x-a(i))/(a(i+1)-a(i)))*(((x-a(i+1))/(a(i)-a(i+1)))**2)d(i)=(((x-a(i+1))/(a(i)-a(i+1)))**2)*(x-a(i))m=y(i)*h(i)+dy(i)*d(i)end subroutine solveprogram mainreal::i,sreal::a(
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 20:21:50
fortran程序,subroutine solvereal::i,x,y,mreal::h(i),d(i),a(i),dy(i)h(i)=(1+2*(x-a(i))/(a(i+1)-a(i)))*(((x-a(i+1))/(a(i)-a(i+1)))**2)d(i)=(((x-a(i+1))/(a(i)-a(i+1)))**2)*(x-a(i))m=y(i)*h(i)+dy(i)*d(i)end subroutine solveprogram mainreal::i,sreal::a(
fortran程序,
subroutine solve
real::i,x,y,m
real::h(i),d(i),a(i),dy(i)
h(i)=(1+2*(x-a(i))/(a(i+1)-a(i)))*(((x-a(i+1))/(a(i)-a(i+1)))**2)
d(i)=(((x-a(i+1))/(a(i)-a(i+1)))**2)*(x-a(i))
m=y(i)*h(i)+dy(i)*d(i)
end subroutine solve
program main
real::i,s
real::a(i),y(i),dy(i)
s=0
open(10,file='data.txt',status='old')
read(10,'(a20)')
do i=1,5
read(10,*) a(i),y(i),dy(i)
call solve
s=s+m
end do
close(10)
end
结果如下:
--------------------Configuration:hermite2 - Win32 Debug--------------------
Compiling Fortran...
F:\fortran wenjian\hermite2\hermite2.f90
F:\fortran wenjian\hermite2\hermite2.f90(2) :Error:A specification expression object must be a dummy argument,a COMMON block object,or an object accessible through host or use association [I]
real::i,x,y,m
------^
F:\fortran wenjian\hermite2\hermite2.f90(12) :Error:A specification expression object must be a dummy argument,a COMMON block object,or an object accessible through host or use association [I]
real::i,s
------^
F:\fortran wenjian\hermite2\hermite2.f90(13) :Error:An automatic object is invalid in a main program.[A]
real::a(i),y(i),dy(i)
------^
F:\fortran wenjian\hermite2\hermite2.f90(13) :Error:An automatic object is invalid in a main program.[Y]
real::a(i),y(i),dy(i)
-----------^
F:\fortran wenjian\hermite2\hermite2.f90(13) :Error:An automatic object is invalid in a main program.[DY]
real::a(i),y(i),dy(i)
----------------^
Error executing df.exe.
hermite2.obj - 5 error(s),0 warning(s)
fortran程序,subroutine solvereal::i,x,y,mreal::h(i),d(i),a(i),dy(i)h(i)=(1+2*(x-a(i))/(a(i+1)-a(i)))*(((x-a(i+1))/(a(i)-a(i+1)))**2)d(i)=(((x-a(i+1))/(a(i)-a(i+1)))**2)*(x-a(i))m=y(i)*h(i)+dy(i)*d(i)end subroutine solveprogram mainreal::i,sreal::a(
一般来说,Fortran 的数组在定义时需要指定其大小.
如果你要用 real :: h(i)
那么 i 必须是确定的值,例如常数,虚参,COMMON 中的变量.
如果定义时尚不能确定大小,你需要使用可变的数组.
这需要书写 allocatable 属性和 allocate 语句.