RE: Using fortran shared libraries from root

From: Fine, Valeri <fine_at_bnl.gov>
Date: Fri, 10 Feb 2006 02:08:10 -0500


One extra advice :)  

If you anticipating calling more then one Fortran subroutine then you may regard creating some C++ class with the bunch of the static methods: one per each your FORTRAN subroutine. This way you simplify your RootCint dictionary creation because instead of editing your LinkDef.h each time you add / remove some FORTRAN subroutine you demand the dictionary for that single C++ class wrapper.  

"F,h"
class F {
private: F(){}
public:
  static F1()'
  static F2();
...
  static FN()
};
 

LinkDef.h;
#pragma link C++ class F;  

F.cxx:
 extrern "C" {
  void fsub1_();
  void fsub2_();
 . . .
 void fsubn_();
}
 

 void F::F1() { fsub1_();} 
 void F::F2() { fsub2_();} 
 void F::F3() { fsub3_();} 
 

etc  

Now from the ROOT prompt you can call  

 root [0] F::F1();  

Cheers, Valeri


From: owner-roottalk_at_pcroot.cern.ch on behalf of Fine, Valeri Sent: Thu 2/9/2006 11:42 PM
To: bourilkov_at_phys.ufl.edu; roottalk_at_pcroot.cern.ch Subject: RE: [ROOT] Using fortran shared libraries from root

You should describe the interface to your FORTRAN subroutine using C-like header file and create the RootCint dictionary for that interface. One is advised to create a C-wrapper around of the Fortran call and create the RootCint dictionary for that wrapper.

MyFortran.h:



 void MyFunction( int a)

MyFortarn.cxx:
extern "C" {
  void myRealFortran_(int *a);
}

void MyFunction(int a)
{
  int fA = a;
   // call the real fortran
   myRealFortran_(&fA);
}

The real life examples can be seen too:

ttp://www.star.bnl.gov/cgi-bin/cvsweb.cgi/StRoot/St_base/StMessMgr.h?rev=1.7 <http://www.star.bnl.gov/cgi-bin/cvsweb.cgi/StRoot/St_base/StMessMgr.h?rev=1.7> http://www.star.bnl.gov/cgi-bin/cvsweb.cgi/StRoot/St_base/StMessMgr.cxx?rev=1.6

Hope this helps.

                    Valeri

________________________________

From: owner-roottalk_at_pcroot.cern.ch on behalf of Dimitri Bourilkov Sent: Thu 2/9/2006 3:10 PM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] Using fortran shared libraries from root

Hi,

    I would like to call from the root command line functions/subroutines from a fortran shared library (.so) built with -fpic. Is this possible? I see in the root pages examples for calling cernlib, but as they are statically built one has to rebuild the root.exe. This is not what I want, I would like to make them accesible from the standard root prompt. Any advice is welcome.

    Best, Dimitri

--
        _/_/_/                             _/_/_/
       _/    _/   Dimitri  BOURILKOV      _/    _/
      _/    _/   University of Florida   _/_/_/
     _/    _/   bourilkov_at_phys.ufl.edu  _/    _/
    _/_/_/                             _/_/_/
Received on Fri Feb 10 2006 - 08:09:06 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET