shrine 发表于 2017-7-8 10:36:18

子程序能作为参数传递吗?

本帖最后由 shrine 于 2017-7-8 10:40 编辑

最近在看最小二乘法minpack,简洁起见,过多参数用省略号表示,fcn是需要自己提供的
subroutine lmder(fcn,......wa4)
      integer ....      
      double .....


      call fcn(m,n,x,fvec,fjac,ldfjac,iflag)
end
      既然要call fcn,那肯定是subroutine,而不是function,但是subroutine怎么能作为参数传递呢?

vvt 发表于 2017-7-8 19:55:44

方法1(假设 fcn 返回 real 类型):
Subroutine Imder( fcn , ... )
Real , external :: fcn
y = fcn(x)
方法2:
Subroutine Imder( fcn , ... )
Interface
real function fcn( x )
    real :: x
end function fcn
End Interface
y = fcn(x)

chiangtp 发表于 2017-8-12 13:22:13

蒐集來的資料, 敬請參考:
页: [1]
查看完整版本: 子程序能作为参数传递吗?