Mapping arrays between C and Fortran

Arrays can be passed between C and Fortran routines when the array passed has its elements in contiguous storage locations. In addition, in a called Fortran routine, the declaration of the array must indicate a constant number of elements along each dimension.

In C, arrays of more than one dimension are arranged in storage in row major order, while in Fortran they are arranged in column major order. You need to reference the corresponding element of the other language by reversing the order of the subscripts. For example, in an array of floating point integers, the C declaration would be float [10][20] while the Fortran declaration would be REAL*4(20,10).

Another difference in using arrays is that unless specified otherwise, the lower bound (the lowest subscript value) of a Fortran array is 1. In C, the lowest subscript value is always 0, so you must adjust either the declared lower bound in the Fortran routine or the subscript you are using when you reference the value in C or Fortran.

For example, the following two arrays have the same storage mapping:
C
float da[10][20];
Fortran
REAL*4 DA(20,10)
The following two elements also represent the same storage:
C
da[4][8]
Fortran
DA(9,5)