Re: Root macro call Fortran subroutines

From: Brett Viren <>
Date: Fri, 25 Aug 2006 14:26:51 -0400

"Weijun Guo" <> writes:

Halliburton uses Root ?!?

> I have some Fortran subroutines. I have source codes and different
> version of Fortran compilers available. Could you possibly send me or
> point me to some examples for calling Fortran subroutines from a root
> macro? For all Fortran routines that I have, the arguments are double
> arrays or integer arrays and they do not explicitly return values.

Here is one way:

  1. In your LinkDef.h file put lines like:

#pragma link C++ function fortsub_;

Where "fortsub" is the name of your FORTRAN sub routine. You need the trailing underscore.

2) Make a "fortsub.h" file that declares "fortsub_". Arrays of doubles or ints are just declared like "double*" or "int*". Say fortsub takes both then you'd do:

// fortsub.h
extern "C" {
void fortsub_(double* darray, int* iarray); }

3) Then generate the dictionary code with rootcint

4) compile and link your .F, the generated dictionary code and any other source files you want.

5) Load lib into root.

It is only the trailing underscore and the need to use

extern "C" { ... }

in the declaration (and knowing how FORTRAN passes arguments) that makes using FORTRAN subroutines any different than C++ functions.

-Brett. Received on Fri Aug 25 2006 - 20:27:12 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:00 MET