如何在Fortran中编写一个将输入和输出都作为参数的函数?例如:
How can I write a function in Fortran which takes both input and output as arguments? For example:
fun(integer input,integer output)我想要使用输出值。我试过类似的东西,但输出变量不包含该值。
I want to make use of the output value. I have tried something like this but the output variable is not holding the value.
具体而言,我从Fortran中调用一个C函数,它将输入和输出作为参数。我能够成功传递输入值,但输出变量没有获取值。
Specifically, I am calling a C function from Fortran which takes input and output as parameters. I am able to pass input values successfully, but the output variable is not acquiring a value.
推荐答案像我这样的Fortran程序员打电话给SUBROUTINE(是的,我们也在Fortran城里喊我们的关键字)。一个函数是一个像这样的返回值的东西:
Your fun() is what Fortran programmers, such as me, call a SUBROUTINE (yes, we shout our keywords in Fortran-town too). A FUNCTION is a value-returning thing like this:
sin_of_x = sin(x)因此,您的第一个决定是您的Fortran代码采用哪种方法。你可能想要使用SUBROUTINE。然后理清你的论点的意图。
So your first decision is which approach your Fortran code will take. You probably want to use SUBROUTINE. Then sort out the INTENT of your arguments.
更多推荐
Fortran函数和返回值
发布评论