There is some main C++ code that will calling a fortran subroutine,
using namespace std;
* Fortran/C++ interoperability
extern "C" void Fortran_f(double**, int);
int i, sz =10;
// Do something with AG
C-function "malloc" for the reallocation purposes in C++ main was using(however, will be provided by the fortran function later).
How to pass AG object to the Fortran function?
My first try is,
USE, INTRINSIC :: ISO_C_BINDING
TYPE(C_PTR) :: PAG
INTEGER, INTENT(IN), VALUE :: SZ
DOUBLE PRECISION, POINTER :: PA(:)
INTEGER :: I, J, M, N
DOUBLE PRECISION. :: X
TYPE(PRV) :: P_PAG
TYPE(PRV),POINTER,DIMENSION( : ) :: AG
TYPE(C_PTR), POINTER :: CPAG
DO I = 1, SZ
! Do something in Fortran code
! AG =>REALLOCATE(AG, new_size) ! My own realloc function
DO I = 1, M
DO J = 1, N
Unfortunately, it didn't work with the following error:
forrtl: severe (408): fort: (7): Attempt to use pointer PA when it is not associated with a target
Only one of the languages should perform the allocations, reallocations and deallocations of objects.
Look at the documentation for the C interoperability features, in particular the means to use/pass Fortran descriptors to C/C++ programs.
As an additional note.
Fortran uses descriptors into an allocatable array that is contiguous. IOW this is not an array of pointers to rows of data.
In C/C++ it is more efficient to allocate a 2D array as a 1D array, possibly sticking the pointer into the C/C++ pointer of the row table, then populate the row table for each stride into the blob that constitutes the 2D array.