Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Fortran Programming Language

F90 to C interface


Dear Group,

Maybe a bit an "off topic" question and I applogize for that in advance. I have already asked is some other place but without any
luck so far.

I want to use the CHOLMOD sparse solver (CHOLMOD is something like sparseblas, Lapack, etc. etc) but this package is written in C
whereas my software is written in F90.  So to be able to use it (properly) I need to write an interface routine for calling this
C-package from my F90 code.

So my first simple question is if somebody has by any chance alread written and interface for calling CHOLMOD?

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!

Many thanks in advance!

Cheers,
Tim

"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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc