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.
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
-1m-1and the second product ism!.So, a proper (but not necessarily efficient) translation could be:
Succinct, close in “spirit” with the F90, but hardly efficient: