“%”是什么意思Fortran 语言中的意思是/做什么?
我正在尝试阅读一些 Fortran 代码,但无法确定 %
(百分号)的作用。
它是这样的:
x = a%rho * g * (-g*a%sigma + m%gb * m%ca * (1.6 * a%rho+g))
它有什么作用?
I am trying to read some Fortran code, but can not determine what the %
(percentage sign) does.
It is in a line like:
x = a%rho * g * (-g*a%sigma + m%gb * m%ca * (1.6 * a%rho+g))
What does it do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Fortran 90 中,它们允许您创建类似于 C++ 中的结构。它基本上充当点 (.) 运算符。
来自http://www.lahey.com/lookat90.htm:
结构(派生类型)
您可以使用以下方式对数据进行分组:派生类型。这使用户能够将内部类型(包括数组和指针)组合成新类型,可以使用百分号作为分隔符来访问其各个组件。 (派生类型在 VAX Fortran 中称为记录。)
!使用派生类型和模块的示例。
In Fortran 90 they allow you to create structures like in C++. It basically acts as the dot (.) operator.
From http://www.lahey.com/lookat90.htm :
Structures (Derived Types)
You can group your data using derived types. This enables users to combine intrinsic types (including arrays and pointers) into new types whose individual components can be accessed using the percent sign as a delimiter. (Derived types are known as records in VAX Fortran.)
! Example using derived types and modules.
%
作为令牌有许多密切相关的用途。随着 Fortran 的发展,这些用途的数量不断增加。回到 Fortran 90,以及问题中看到的用法,
%
用于访问派生类型的组件。考虑派生类型a_t
以及该类型的对象a
:a 的组件
。从问题中可以看出,这些组件可以在表达式中使用(例如rho
和sigma
可以使用a%rho
和a%sigma
访问a%rho * g
),也可以是赋值的左侧(a%rho =1.
)。派生类型的组件本身可能是派生类型的对象:
因此在单个引用中可能会多次出现
%
:这里,派生类型的组件
rho
派生类型对象a
本身是b
的组件,是赋值的目标。人们可以在一个引用中看到相当可怕的%
数量,但零件引用始终是从左到右解析的。来到 Fortran 2003,人们就会看到
%
通过其他几种方式与派生类型相关:考虑派生类型
对象
a
有一个长度类型参数和一个类型绑定过程。在像绑定f
这样的表达式中,派生类型对象被引用。
可以引用
a
的参数n
,就像可以引用组件
x
一样多。最后,从 Fortran 2008 开始,
%
可用于访问复杂对象的实部和虚部:%
as a token has a number of closely related uses. As Fortran has developed those uses have increased in count.Going back to Fortran 90, and the use seen in the question,
%
is used to access the components of a derived type. Consider the derived typea_t
with objecta
of that type:The components
rho
andsigma
ofa
may be accessed witha%rho
anda%sigma
. As can be seen in the question, these components may be used in expressions (such asa%rho * g
) or they may be the left-hand side of an assignment (a%rho=1.
).A component of a derived type may itself be an object of derived type:
and so there may be multiple appearances of
%
in a single reference:Here, the component
rho
of the derived type objecta
, which is itself a component ofb
, is the target of assignment. One can see a quite horrifying count of%
s in one reference, but the part references are always resolved from left to right.Coming to Fortran 2003, one then sees
%
relating to derived types in a couple of other ways:Consider the derived type
The object
a
has a single length-type parameter and a type-bound procedure. In an expression likethe binding
f
of the derived type object is referenced.The parameter
n
ofa
may be referenced asmuch as the component
x
may be referenced.Finally, from Fortran 2008,
%
may be used to access the real and imaginary parts of a complex object:它是派生类型的部分标识符。看看这个。 http://www.lahey.com/lookat90.htm
It's a part identifier for a derived type. Check this out. http://www.lahey.com/lookat90.htm