Conditions:To use the Fortran subroutines and functions 3 pre-conditions have to be met:
It is provided by "cons" for all source files with the upper case "*.F" extension
It has to be written "by hand"
The Fortran Run-time libraries are provided by "root4star". They are not provided by the "plain" root.exe
The STAR "cons" automatically creates the RootCint dictionary for the all header files it discovery.
To use the fortran subroutine from ROOT C++ macro you are advised to use STAR build env as follows
Let's assume you need to call the subroutine:
SUBROUTINE FRAGMF(IPART,X,Q2,XGLUE,XUQ,XDQ,XSQ,XUSEA,XDSEA,XSSEA,
& XCHARM,XCHARMS,XBEAUTY,XBEAUTYS)
from C++ code (including ROOT macro).
You should:
where
Fragmf.h
: defines the C++ interface for your fortan code
#ifndef STAR_FRAGMF_H
#define STAR_FRAGMF_H
#include "TObject.h"
class Fragmf {
public:
void operator()
(int IPART, double &X, double &Q2, double &XGLUE
, double &XUQ, double &XDQ, double &XSQ
, double &XUSEA,double &XDSEA,double &XSSEA
, double &XCHARM, double &XCHARMS, double &XBEAUTY
, double &XBEAUTYS) const;
ClassDef(Fragmf,0)
};
#endif
Fragmf.cxx
: the implementation of your C++ code:
#include "Fragmf/Fragmf.h"
ClassImp(Fragmf)
extern "C" {
// definition fo the FORTRAN sunbroutine interface
void fragmf_(int *, double *X, double *Q2, double *XGLUE
, double *XUQ, double *XDQ, double *XSQ
, double *XUSEA, double *XDSEA, double *XSSEA
, double *XCHARM, double *XCHARMS,double *XBEAUTY
, double *XBEAUTYS);
}
void Fragmf::operator()
(int IPART, double &X, double &Q2, double &XGLUE
, double &XUQ, double &XDQ, double &XSQ
, double &XUSEA,double &XDSEA,double &XSSEA
, double &XCHARM, double &XCHARMS, double &XBEAUTY
, double &XBEAUTYS) const
{
// definition of the C++ wrapper to simplify the FORTRAN
// subroutine invocation
int i = IPART;
fragmf_(&i, &X, &Q2, &XGLUE, &XUQ
, &XDQ, &XSQ, &XUSEA, &XDSEA
, &XSSEA,&XCHARM, &XCHARMS,&XBEAUTY,&XBEAUTYS);
}
3. You can add the ROOT C++ macro to test your inteface
StRoot/Fragmf/Fragmf.C
:
{
gSystem->Load("Fragmf");
int IPART =8;
double X,Q2,XGLUE, XUQ, XDQ, XSQ;
double XUSEA,XDSEA,XSSEA, XCHARM, XCHARMS, XBEAUTY;
double XBEAUTYS;
Fragmf fragmf;
// use "operator()" to proviide Fortran "Look and Feel"
fragmf(IPART,X,Q2,XGLUE, XUQ, XDQ, XSQ
,XUSEA,XDSEA,XSSEA, XCHARM, XCHARMS, XBEAUTY
,XBEAUTYS);
printf(" The values from Fortran:\n"
" %f %f,%f, %f, %f, %f \n"
" %f,%f,%f, %f, %f, %f %f\n"
, X,Q2,XGLUE, XUQ, XDQ, XSQ
, XUSEA,XDSEA,XSSEA, XCHARM, XCHARMS, XBEAUTY
, XBEAUTYS);
}
Now, you are ready to create the shared library with "cons"
> cons
and execute it with the ROOT
> root.exe -q StRoot/Fragmf/Fragmf.C
or
> root4star -q StRoot/Fragmf/Fragmf.C
One needs the very "root4star" as soon his / her Fortran code requires some Fortran Run-Time functions. For example it calls the Fortran I/O or PRINT statements.
In real life, you may not create a dedicated subdirectory StRoot/Fragmf you can add the 3 files in question to any existent STAR offline package.