Fortran Coder

查看: 8205|回复: 2
打印 上一主题 下一主题

[子程序] 子程序的某个形参是函数

[复制链接]

130

帖子

10

主题

0

精华

大师

F 币
617 元
贡献
372 点

贡献勋章管理勋章帅哥勋章元老勋章星光勋章规矩勋章

楼主
发表于 2018-6-14 00:57:54 | 显示全部楼层
[Fortran] 纯文本查看 复制代码
module rksuite_90_prec
  implicit none
  integer, parameter :: wp=selected_real_kind(P=15)
end module rksuite_90_prec

module rksuite_90
  implicit none
contains
  recursive subroutine range_integrate_r1(comm,f,t_want,t_got,y_got,yderiv_got,flag)
    implicit none
    real :: comm, t_want, t_got, y_got, yderiv_got, flag
    interface
       function f(t,y)
          use rksuite_90_prec, only:wp
          implicit none
          real(kind=wp), intent(in) :: t
          real(kind=wp), dimension(:), intent(in) :: y
          real(kind=wp), dimension(size(y,1)) :: f
       end function f
    end interface
    !...
  end subroutine range_integrate_r1
end module rksuite_90

program ode
  use rksuite_90
  implicit none
  real :: comm, t_want, t_got, y_got, yderiv_got, flag
  interface
     function f(t,y)
       use rksuite_90_prec, only:wp
       implicit none
       real(kind=wp), intent(in) :: t
       real(kind=wp), dimension(:), intent(in) :: y
       real(kind=wp), dimension(size(y,1)) :: f
     end function f
  end interface

  call range_integrate_r1(comm,f,t_want,t_got,y_got,yderiv_got,flag)

end program ode

function f(t,y)
  use rksuite_90_prec, only:wp
  implicit none
  real(kind=wp), intent(in) :: t
  real(kind=wp), dimension(:), intent(in) :: y
  real(kind=wp), dimension(size(y,1)) :: f
  f(1) = y(2)
  f(2) =-y(1)
end function f
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-15 16:32

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表