- General information
- Data readiness
- Grid and Cloud
- Infrastructure
- Online Computing
- Software Infrastructure
- Batch system, resource management system
- CVS->Git
- Computing Environment
- Facility Access
- FileCatalog
- HPSS services
- Home directories and other areas backups
- Hypernews
- Installing the STAR software stack
- Provision CVMFS and mount BNL/STAR repo
- RCF Contributions
- Security
- Software and Libraries
- Storage
- Tools
- Tutorials
- Data Carousel Quick Start/Tutorial
- Guide to AFS and ACLs
- How to determine what is happening in slow or stuck processes?
- How to use FORtran from a ROOT macro
- How to use valgrind
- Howto run pythia6/8 or hijing or... without running starsim
- Introduction to STAR software and makers
- Quick guide on CVS in STAR
- Setting up your computing environment
- StEvent/Special documentation
- UML Class Diagram
- Unix command location
- Video Conferencing
- Web Access
- Machine Learning
- Offline Software
- Production
- S&C internal group meetings
- Test tree
Calling a FORtran subroutine from ROOT
Updated on Thu, 2009-07-09 08:56 by testadmin. Originally created by fine on 2008-06-09 15:11.
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:
- Create a directory mkdir StRoot/Fragmf
- Add to that directory your fortran file with ".F" extension (upper case "F"), for example "fragmf.F"
- 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.
»
- Printer-friendly version
- Login or register to post comments