Passing a 2 dimensional array from fortran to c++



Hello all
I have a two dimensional array (the dimensions are not known) that
needs to be passed
to fortran from c++.

Say in my c++ code I have;

extern "C" { void foo_(float **, int &, int &); }

int main()
{
............
..............
int rows, columns;
float **array2d; // Now i need to pass this to the fortran code, the
allocation of the array and
// and filling it is done in the fortran code.
// How do i pass this to the fortran subroutine now, i did it this way

foo_(array2d, rows, columns);

// One more question, do i need to do the allocation and stuff here
again
// Do some stuff to manipulate with the array2d

return 0;

}

and my Fortran routine:

subroutine foo(arr,rows,columns)
integer rows, columns
real*8 ,allocatable:: arr (:,:)
! do some stuff to allocate the arrray and fil the stuff

end subroutine

It would be of great help if anyone could tell me how to do this

Regards
Sam

.



Relevant Pages

  • Re: What I can to do with old PL/1 code?
    ... I would assume that in normal use above is declared in a calling unit (main ... and below is in a called unit (subroutine?) ... however there is no size allocation assigned to A array below, ... But a main/subroutine algorithm might be coded in Fortran: ...
    (comp.lang.pl1)
  • Re: equivalencing allocatable arrays
    ... them do, nowadays), then you can have subroutine dummy arguments that are ALLOCATABLE -- that is, you can do the allocation in the subroutine. ... I'm using a FORTRAN77 compiler with some Fortran 90 ... Why not 'upgrade' to Fortran 95? ...
    (comp.lang.fortran)
  • Re: newbie: array passing problem
    ... I'm not quite sure what you mean there, but if you want to perform some task on specific "column" of a two dimensional array then you can do so in the following manner. ... In older FORTRAN, it was often the case that subroutines were passed the address of the starting array location and in the subroutine a multiply-dimension array would then be referenced by only a single index. ...
    (microsoft.public.vb.general.discussion)
  • Re: Fortran based MEX w/ COMMON/SAVE
    ... I believe dat (pointer to the array) and the ... SAVE at the begining of each subroutine is a bit unusual to me. ... > to unload it if there isn't a Fortran END or STOP statement. ... interaction w/ Matlab). ...
    (comp.soft-sys.matlab)
  • Re: Help Constructing Fictional Cross-Religious Movement
    ... You know how to do something in Fortran that I ... >don't know how to do despite being pretty familiar with it, COBOL ... > subroutine point ... >was finding a programming problem that seemed reasonably amenable to ...
    (rec.arts.sf.composition)