Fortran函数和返回值 [英] Fortran functions and return values

查看:1003
本文介绍了Fortran函数和返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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函数和返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆