"Tim Springer" <Tim.Sprin
@solenix.ch> writes:
> In case the answer to this first question in "no" can anybody give me
> some hints and tips on how a F90 interface to a C-library should
> look!? I am an experienced fortran programmer (many years with F77 and
> the last 3 years with F90) but I have little to no knowledge on C. So
> any hints/tips/pointers/examples are welcome!
I had a while ago a similar problem (interfacing Fortran code with C
libraries); theoretically you would be able to use the Fortran2003
C-interop stuff (especially C_F_POINTER), but the compiler support at
the moment is ... sparse; g95 and gfortran have some capabilities, Sun's
f95 has a usable ISO_C_BINDING module which I had used (but had to ditch
the Sun compiler because MVAPICH/VAPI wasn't compilable with it).
In the end I had written a simple wrapper routine in C for every used
library function which has a signature like
void foo_ (<type>* a, <type>* b, ..., <type>* status) { ... }
and calls the library function "foo" with pointers dereferenced where
necessary. A Fortran module was also written containing interface
definitions for the wrapper routines.
Regarding arrays, you have to be careful: onedimensional continuous
arrays ("vectors") can be passed as an assumed-size array (like C does
it), but for arrays with rank 2 or more, you either have to use the
C-interop capabilities where available, try your luck with the CHASM
library or resort to Cray pointers (what I was forced to do).
On a few occasions it was helpful to look at the source of any MPI
library for some common problems and solutions.
Sebastian