私は関数integ
を別の関数rter3
から呼び出しました。私はinteg
の値をinteg
関数から出力し、正当な値を出力します。しかし、integ
の値をrter3
に印刷すると、0.00
が印刷されます。私はなぜそれがそれをするのか理解することができるすべてを試みたが、把握できなかった。ここで私を助けてください。ありがとう。Fortran関数がメインプログラムに値を返しません
function rter3(z,c1,nx1,xarray,xlocation,angl3r,gamr,probr,aaa,da1)
use data
integer:: z,o,nx1,lc
double precision:: c1(nx1),w1,w2,rter3,angl3r,gamr,probr(100),aaa,da1,rati2,xarray(nx1),xlocation,div1
double precision:: variable
dx=0.1
rati2=20.0
!write(*,*) z,o,nx1,xlocation,angl3,gam
w1=div1(c1(z-1),c1(z),dx)
w2=div1(c1(z),c1(z+1),dx)
variable=integ(nx1,c1,xarray,xlocation,dx,angl3r,gamr,probr,aaa,da1,w1,w2)
rter3=rati2*variable
write(*,*) "rter3=", rter3, variable, rati2, xlocation, gam, angl3, da1
end function rter3
function integ(nxx,hfield,xfield,loc1,diff,angl3,gam,prob,afield,dprob,ab2,af2)
implicit none
integer :: l,nxx,dui,kk,indx,indt
double precision:: du(101),prob(100),am1,a,ap1,angl3,gam,diff,dprob,integ,function12,afield(100),xfield(nxx)
double precision:: loc1,loc2,hfield(nxx),am2,ap2,ab2,af2
!write(*,*) 'test loop', loc1, diff, angl3, gam, dprob
do kk=1,100
do l=1,nxx
if (0.95*xfield(l)>=loc1-afield(kk).and. 1.05*xfield(l)<loc1-afield(kk)) then
dui=l
!call exit()
endif
enddo
!dui= loc1-kk
!write(*,*) "Entered integ", dui
!write(*,*) dui
if (dui<=3) then
dui=3
endif
if (dui>= nxx-2) then
dui=nxx-2
endif
am1=hfield(dui-1)
am2=hfield(dui-2)
a=hfield(dui)
ap2=hfield(dui+2)
ap1=hfield(dui+1)
du(kk)=abs(prob(kk)*(function12(am2,am1,ap1,ap2,diff,angl3,gam,ab2,af2))*dprob)
enddo
integ=sum(du)
write(*,*) "integration value=", integ, nxx, loc1, diff, angl3, gam, dprob
end function integ
これらは、参照する個々の機能です。何か間違っていると感じたら教えてください。コード全体が非常に大きいですが、あなたがそれを見る必要があると感じたら、それを添付します。再度、感謝します。
こんにちは。お返事をありがとうございます。はい、あなたは正しかった、私は当初、関数rter3で使用されている "データ"と呼ばれるモジュールにすべての手順(rter3とinteg、両方とも倍精度)を配置しました。私はまた、暗黙のnoneをソースコードに使用しました。私ができることを他に教えてもらえますか?再度、感謝します。 – tacqy2
ねえ。代わりにrter3で 'double precision :: integ'を定義していました。どういうわけかモジュールがうまく動作しませんでした。その考えに感謝します。 – tacqy2
あなたは必要な順番で物を集めていますか?それは言語標準の外にあるため説明できない傾向があります。モジュールとメインプログラムが別々のファイルにある場合、通常、モジュールファイルはコンパイルコマンドのメインプログラムの前にある必要があります。ソースコードが1つのファイルにある場合、モジュールはそれを使用するルーチンの前に置く必要があります。 –