Mixing C++/Fortran using Two-Dimensional Array

From: WereWolf (werewolf_at_phreaker.net)
Date: 05/23/04


Date: Sun, 23 May 2004 09:36:24 +0200

Hi everybody.

I'm writting a code.cpp to call a fortran routine.
In the code.cpp, I allocate dynamically two 2-dim arrays with values I
calaculated before.
I should pass these arrays in argument to the fortran routine to read the
1st array and fill up the 2nd array in it...

I don't know how to do that in fortran.
I'm not an expert (I never used fortran before).
I tried simple static C-style arrays tab1[const1][const2] and
tab2[const1][const2] and it works fine with these fortran lines:

 ...
 integer, intent (in), dimension(nsite,natm) :: attype
 double precision, intent (inout), dimension(nsite,natm) :: result
 do i=1,nsite
 do j=1,natm
 write(*,*) i,j,attype
 result(i;j)=i+j
 enddo
 enndo
 ...

But as I said, my problem is that I calculate nsite and natm in the C++
routine so I cannot use them as size of an array (not constant).
So I need to dynamically allocate them...
Is there an equivalent type in fortran for the int ** type ? (I saw a
pointer type but I don't know if I can use it)
If yes, what should I declare in the fortran routine and how to use it ?
(if I know this pointer will point a zone of memory allocated by the c++
routine)

Summary:
There is a c++ routine in which 2 values are calculated.
These values are used to dynamically allocate 2 2-dim arrays.
The c++ routine fills up the 1st array.
Then it has to call a fortran routine with these arrays.
The fortran routine fills up the 2nd array.
In the end it reads the 2nd array filled up by the fortran routine.

I hope you understand what I wanted to tell you.

Thank you very much for you help !

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.689 / Virus Database: 450 - Release Date: 21/05/2004


Relevant Pages

  • Re: Allocation interoperability (Fortran/C)
    ... receive that as an explicit-shape array. ... Effectively how are you going to indicate to the Fortran routine ... So now I am considering calling a C allocation function which in return ... repeat for the next timestep. ...
    (comp.lang.fortran)
  • Storing/Retrieving TYPEs with ALLOCATABLE components (TR) (long)
    ... tBrd, including array descriptor of tEn )). ... Without previous DEALLOCATE, the allocate line fails at run time with message ... the fact that I'm loading an invalid descriptor tBrd%tEn from the file... ... status (which is not possible according to Standard, but then BINARY files ...
    (comp.lang.fortran)
  • Re: Storing the size of an array in the structure itself
    ... >> I think every C programmer can relate to the frustrations that malloc ... >> the size of an array must be stored separately to be a nightmare. ... is anything more than just that - a chunk of memory. ... > Otherwise you couldn't tell it how much to allocate. ...
    (comp.lang.c)
  • determining available space for Float32, for instance
    ... I am looking for a way to determine the maxium array size I can allocate ... We do not want a solution that requires recompiling Python, ... agents may be households that choose a new gridcell to live in. ... Each attribute of a dataset has such a 2D array. ...
    (comp.lang.python)
  • Re: output of allocatable array of strings==> blank?
    ... Inside the subroutine, I declare subheader as ... declare the subheader as a BIG_NUMBER of strings array. ... ALLOCATE the array of the right size and pass it, ...
    (comp.lang.fortran)