Search code examples
cfortran77

passing 2d array from C to fortran77


I have the following array in fortran77 dec(3, 25000), even if only the 8898 out of the 25000 positions in the second dimension are used.

I'm passing this array as a parameter, together with other arrays, to a C function. Even though the other parameter's values seem to be right, the dec() values are wrong.

I've tried passing only the dec() array and the results are the same. The value in dec(1,1) (fortran77) is equal to the value in dec[0][0] (C), but for random positions in the array I do not get the same values in fortran77 just before calling the C function and in the C function.

Any idea why this happens?

The array is declared as real*8 dec(3,25000) in fortran, and as int dec[3][25000] in C.

Thanks in advance


Solution

  • Keep in mind that the major order for bidimensional arrays is swapped between the two languages. So dec[i][j] in one language would be dec[j][i] in the other, plus index base adjustment as you have already found out.