Calling a FORtran subroutine from ROOT

Under:

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:

  1. Create a directory mkdir StRoot/Fragmf
  2. Add to that directory your fortran file with ".F" extension (upper case "F"), for example "fragmf.F"
  3. Create there 2 C++ files: "Fragmf.cxx" "Fragmf.h"

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.