私は Fortran プログラミングの初心者です。2 つの .f90 ファイルがあります。
fmat.f90
function fmat(t,y)
implicit none
real::t
real::y(2)
real::fmat(2)
fmat(1) = -2*t+y(1)
fmat(2) = y(1)-y(2)
end function fmat
そして、main.f90 は次のようになります。
program main
implicit none
real::t
real::y(2)
real::fmat(2)
real::k(2)
t=0.1
y(1)=0.5
y(2)=1.4
k=fmat(t,y)
write(*,*) k
end program main
だから、私は0.3 -0.9を期待しています。しかし、次のエラーメッセージが表示され続けます。
ifort fmat.f90 main.f90
main.f90(13): error #6351: The number of subscripts is incorrect. [FMAT]
k=fmat(t,y)
--^
compilation aborted for main.f90 (code 1)
どんな助けでも大歓迎です!
!==== 編集 ====
マークの回答に感謝します。「サブルーチン」アプローチを使用して、実際にエラーなしで個別のファイルをコンパイルできました。
main.f90
program main
implicit none
real::t
real::y(2)
real::k(2)
t=0.1
y(1)=0.5
y(2)=1.4
call fmat_sub(t,y,k)
write(*,*) k
end program main
fmat_sub.f90
subroutine fmat_sub(t,y,k)
implicit none
real::t
real::y(2),k(2)
k(1) = -2*t+y(1)
k(2) = y(1)-y(2)
end subroutine fmat_sub