次のサブルーチンでは、という名前の文字列変数を渡しますstr
。、、の場合'poly'
、事前定義されたアクションがあります(以下のコードを参照)。使用する関数をユーザーに指定して、それを文字列変数として渡してもらいたいのですが。'gaus'
'slat'
fval =
あれは ...
の場合str = '3*cos(i*t)'
、私はfval
に等しくなりたい3*cos(i*t)
です。入力した文字列をFortranで実行するコマンドとしてFortranに解釈させるにはどうすればよいですか?
subroutine f(fval, i, t, str)
implicit none
integer, parameter :: ikind = selected_int_kind(8)
integer, parameter :: dbl = selected_real_kind(15,307)
integer(kind = ikind) :: i
real(kind = dbl) :: fval, t
character str*100
if(str .eq. 'poly') then
fval = t**i
elseif(str .eq. 'slat') then
fval = exp(-i*t)
elseif(str .eq. 'gaus') then
fval = exp(-i*t*t)
else
fval = ???
endif
end subroutine