I am working with both C++ and Fortran code. The C++ code needs to call a Fortran subroutine. One parameter of the Fortran subroutine has Fortran type complex.
The C++ code is in one file, and the Fortran code subroutine is in another file. I am using gcc and gfortran on a 64-bit GNU/Linux system.
Here is a snippet showing the Fortran subroutine declaration (and a few additional lines):
SUBROUTINE minp (AMP,L,L2,FMINP,PHI)
REAL*4 AMP( L ),FMINP( L )
COMPLEX PHI( L )
In the C++ file, I understand that arguments passed to the Fortran code need to be passed by reference, and not by value. The Fortran subroutine is declared as a function in the C++ code (at the top of the source code file) using the extern keyword.
extern "C"
{
minp_ (float *amp, int &L, int &L2, float *fminp, complex *phi);
}
However, the last parameter of the function is a complex C array. How might it be possible to:
- Allocate memory for a complex array in C/C++ to be passed in as the
phiargument? - Pass the array as an argument to the Fortran subroutine in such a way that the memory can be used by the Fortran code?