Presentation is loading. Please wait.

Presentation is loading. Please wait.

Alberto Fassò Endre Futó

Similar presentations


Presentation on theme: "Alberto Fassò Endre Futó"— Presentation transcript:

1 Alberto Fassò Endre Futó
FLUKA in ROOT Alberto Fassò Endre Futó

2 Introduction FLUKA is written in FORTRAN77 (~900 routines)
It is excluded to rewrite it in C++ Present use of FLUKA: - FORTRAN user routines having access to the information in the COMMONs Solution: - Rewrite COMMONs to C++ header files - Rewrite only user routines to C++ (better: call from FORTRAN user routines corresponding C++ procedures)

3 Main differences between FORTRAN and C++ (1)
Arrays: FORTRAN: columnwise (leftmost subscripts vary fastest) C++: rowwise (rightmost subscipts vary fastest) Subroutine arguments: FORTRAN: to be passed by reference C++: non-array arguments passed by value, therefore declare them to be passed by ref or const ref C++: array args are declared arrays, but actually passed by ref, because C++ converts use of array name to a pointer to the array's first element C++: args not modified by FORTRAN to be declared const

4 Main differences between FORTRAN and C++ (2)
Be aware of storing vars in memory LOGICAL variables exponent should be e (not d) If in C++ number starts with 0 -> octal number Character variables (no string in FORTRAN) No blanks in C++ variable names Problem of EQUIVALENCE -> union Input/Ouput: avoid doing input or output from both languages with the same file or device There may be implementation-specific behaviours, but generally the output of the two will be intermingled

5 Rewrite COMMONs to C++ header files
Perl script c2h.pl far from being perfect, question of time and effort to write a better one, therefore always check: Multidimensional arrays (swap dimensions) Arrays dimensioned X(n:m) -> X[n-m+1] CHARACTER* vars -> swap dim and char size LOGICAL vars -> all should be integers All comment lines All continuation lines All unions created from EQUIVALENCEs All double constants -> exponent should be e All exp constants -> exp cannot start with 0

6 Rewrite COMMONs to C++ header files
extern “C” { typedef struct { Double_t whasou[12]; Double_t tkesum; Int_t lussrc; } episorCommon; #define EPISOR COMMON_BLOCK(EPISOR,episor) COMMON_BLOCK_DEF(episorCommon, EPISOR); typedef struct { Char_t sdsou[8]; } chepsrCommon; #define CHEPSR COMMON_BLOCK(CHEPSR,chepsr) COMMON_BLOCK_DEF(chepsrCommon, CHEPSR); } * /EPISOR/ LOGICAL LUSSRC CHARACTER SDUSOU*8 COMMON /EPISOR/ WHASOU(12),TKESUM,LUSSRC COMMON /CHEPSR/ SDUSOU

7 Mixing FORTRAN and C++ header.h
#ifndef __CFORTRAN_LOADED #include “....../root/include/cfortran.h” #endif #ifndef WIN32 #ifndef WIN32 #define flukam flukam_ #else #define flukam FLUKAM #endif extern “C” { void flukam (const int& iflgeo); // COMMON /AAAAAA/ AA, BB, II, JJ typedef {double aa; double bb; int ii; int jj;} aaaaaaCommon; #define AAAAAA COMMON_BLOCK(AAAAAA,aaaaaa) COMMON_BLOCK_DEF(aaaaaaCommon,AAAAAA); }

8 Mixing FORTRAN and C++ main.cxx + flukam.f
SUBROUTINE FLUKAM (IFLGEO) REAL *8 AA, BB COMMON /AAAAAA/ AA,BB,II,JJ AA = 1. BB = 2. II = 10 JJ = 20 ICODE = 100 MREG = 17 CALL MGDRAW (ICODE,MREG) RETURN END #include “header.h” int main () { flukam (0); return (0); }

9 Mixing FORTRAN and C++ mgdraw.cxx
#include <iostream.h> #include <iomanip.h> #include “header.h” #ifndef WIN32 #define flukam flukam_ #else #define flukam FLUKAM #endif extern “C” { void mgdraw (int& icode, int& mreg) { cout << “ ICODE=” << icode << “ MREG=” << mreg << endl; cout << “ AA=” << AAAAAA.aa << “ BB=” << AAAAAA.bb << endl; cout << “ II=” << AAAAAA.ii << “ JJ=” << AAAAAA.jj << endl; } }

10 Mixing FORTRAN and C++ compiling and linking
g++ -c main.cxx g++ -c mgdraw.cxx g77 -c flukam.f g++ -o mixedprog main.o mgdraw.o flukam.o mixedprog ========================== Results ======================= ICODE=100 MREG=17 AA=1. BB=2. II=10 JJ=20

11 Mixing FLUKA and ROOT compiling and linking
In the C++ user routine include all necessary header files of ROOT, e.g. #include “...../root/include/TObject.h” all header files containing variables of COMMONs to be used, e.g. #include “ /fluka/flukacppheaders/Ftrackr.h” Modify the lfluka linker file replace g77 by g++ Add library g2c $F77 $FFLAGS l${LIBF} ${LIBA} -lg2c


Download ppt "Alberto Fassò Endre Futó"

Similar presentations


Ads by Google