Fortran90 到 C# 的转换问题
我正在将一些 Fortran90 代码转换为 C#。我对Fortran77有一些了解,但对Fortran90不熟悉。我遇到了以下代码行,我不确定如何翻译。
C1 = real(product((/(-1,i1=1,m-1)/))*product((/(i1,i1=2,m)/)))
我认为这应该转换为:
int product1 = -1; int product2 = 1;
for (int i1 = 1 ; i1 <= (m-1); i1++)
{
product1 *= -1;
}
for (int i2 = 2, i2 <= m; i2++)
{
product2 *= i2;
}
float C1 = (float)(product1 * product2);
我的不确定性源于这样一个事实:存在用于初始化数组的隐含 do 循环构造;即,
A = (/2*I, I = 1,5/)
但我从未见过在相关 Fortran 语句中使用“产品”一词。我知道有一个用于向量或矩阵乘法的内在函数,称为 PRODUCT,但“product”在我正在使用的代码中不是数组,并且内在函数 PRODUCT 的语法使用 MASK,所以很明显我的语句没有使用此函数。
任何见解或帮助将不胜感激。谢谢。
I am converting some Fortran90 code to C#. I have some knowledge of Fortran77 but am not familiar with Fortran90. I have run across the following line of code that I am not certain how to translate.
C1 = real(product((/(-1,i1=1,m-1)/))*product((/(i1,i1=2,m)/)))
I am thinking this should be converted as:
int product1 = -1; int product2 = 1;
for (int i1 = 1 ; i1 <= (m-1); i1++)
{
product1 *= -1;
}
for (int i2 = 2, i2 <= m; i2++)
{
product2 *= i2;
}
float C1 = (float)(product1 * product2);
My uncertainty stems from the fact that there exists an implied do loop construction for initializing arrays; i.e.
A = (/2*I, I = 1,5/)
but I have never seen the word "product" used as in the Fortran statement in question. I know there is an intrinsic function for vector or matrix multiplication called PRODUCT but "product" is not an array in the code I am working with and the syntax of the intrisic function PRODUCT uses MASK so clearly my statement is not using this function.
Any insight or help would be greatly appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您分解各个部分并打印它们,您会注意到这些只是使用简洁的矢量化术语创建的术语:
另一件事需要注意的是
product()
不需要 3 个参数。第二个参数(要使用的维度)和第三个参数(数组掩码)不是必需的。此时很明显,第一个产品实际上是
-1
m-1
,第二个产品是m!.
因此,正确的(但不一定有效)翻译可能是:
简洁,与 F90 的“精神”接近,但效率很低:
If you decompose the parts and print them, you'll notice these are simply terms created using concise vectorized terms:
The other thing to note is that
product()
does not require 3 arguments. The second argument (the dimension to use) and the third argument (an array mask) are not required.At this point it becomes clear that the first product is actually
-1
m-1
and the second product ism!
.So, a proper (but not necessarily efficient) translation could be:
Succinct, close in "spirit" with the F90, but hardly efficient: