小编Hor*_*sch的帖子

如何将具有多个参数的函数传递给期望只有一个参数的函数的子例程?

我有一个子例程(最小示例)

subroutine treatfunction(f,input,output)
   external, real::f
   real, intent(in):: input
   real, intent(out):: output

   output = f(input) + f(1.0)  ! i.e. f has only one argument
end subroutine
Run Code Online (Sandbox Code Playgroud)

和带有两个参数的函数

real function fun(x,a)
   real,intent(in)::x,a
Run Code Online (Sandbox Code Playgroud)

现在,对于a运行时的给定值,我想传递funtreatfunction。所以理想情况下,我想称呼类似

call treatfunction(fun(:,a=a0), input=myinput, output=myoutput)
Run Code Online (Sandbox Code Playgroud)

使用Fortran2003功能gfortran-5支持进行此操作的最优雅的方法是什么?

当然,我可以在其中插入一个可选的哑元参数atreatfunction并在子例程的主体中f使用f(x)f(x,a)视情况present(a)而定。但是更改子例程并不理想。

fortran gfortran

3
推荐指数
1
解决办法
738
查看次数

如何在R中获得自午夜以来经过的毫秒数?

在 strptime 和 as.POSIXct 的帮助下,POSIXlt 和 POSIXct 类似乎只记录整秒。

(我需要毫秒将它们作为种子传递给共享对象中的随机数生成器。)

r

1
推荐指数
1
解决办法
928
查看次数

标签 统计

fortran ×1

gfortran ×1

r ×1