You are on page 1of 3

mcfarljm / fortwrap

No description, website, or topics provided.

250 commits 1 branch 26 releases Fetching contributors MIT

Fetching latest commit…





FortWrap is a python script that parses Fortran 90/95/200X source files and generates wrapper code for interfacing with the
original Fortran code from C++. FortWrap is intended to be used with Fortran code that takes an object oriented approach
and makes use of Fortran derived types. The resulting wrapper code provides a C++ interface that wraps the Fortran derived
types with C++ "proxy classes".

Currently, FortWrap is targetted at the gfortran compiler, but the generated C++ code should work with any C++ compiler,
including g++.

Fortran derived types wrapped in C++ proxy classes
Experimental support for polymorphism (CLASS variables)
Arrays wrapped with C++ vectors
Support for optional arguments
Support for wrapping procedure pointers
Support for string arguments
Fortran doxygen comments transferred to C++ header files
Name mangling support for gfortran compiler
Wrappers respect Fortran public/private statements
Generated code can be re-wrapped with swig -c++

GitHub - mcfarljm/fortwrap 1 sur 3

make it executable and place it in your ‐h to print usage information. Execute . The tests directory provides working examples of most of the main FortWrap features. " dtor " procedures are automatically called by the C++ destructor. execute make to compile and link a simple test program./.n. for example c_arrays. Then change to a test directory. Multiple constructors are supported. For more details regarding the Fortran constructs that FortWrap is set up to to generate wrapper code. refer to the documentation and the tests directory. tests/arrays. FortWrap is not intended to wrap legacy code and should not be used with Fortran 77 is to execute all tests. Examples For simplicity. Then execute make to build the simple test program in that [args] . FortWrap by default wraps the routine as a static method of the special "utility class" FortFuncs (this can be overriden with the ‐‐global option) .n) TYPE(Object) :: o INTEGER. However. The root directory contains a python script run_tests. Notes The internals of FortWrap are in a stable state and have been used successfully to wrap very large Fortran projects (~40. ALLOCATABLE :: x(:) END TYPE Object CONTAINS SUBROUTINE default_ctor(o. which are defined in run_tests. 2 sur 3 https://github. To manually run a test. Running FortWrap fortwrap. require different FortWrap options. When the first argument is not a derived is a standalone executable python script that may be run using either python fortwrap. For each test. In particular. INTENT(in) :: n ALLOCATE(o%x(n)) END SUBROUTINE default_ctor SUBROUTINE value_ctor(o. some of the examples below are not shown with derived types. for example. For example: MODULE m TYPE Object REAL. FortWrap is not intended to wrap all Fortran constructs. the script will change to the individual test . FortWrap is geared towards wrapping derived types and procedures that operate on . Optionally. and finally run the test program. Before running the ‐g ‐d wrap to generate the C++ wrapper code (some tests. make sure that gfortran is installed. execute fortwrap. first make sure the compiler specified in tests/Tests.000 lines of code). Derived Types " ctor " procedures are wrapped as C++ constructors. Running the tests The easiest way to get started is to look at the simple test programs in the tests directory. Installation Download fortwrap. Documentation Refer to the documentation at docs/manual../ [args] or fortwrap. Use fortwrap.cpp. INTENT(in) :: n GitHub .val) TYPE(Object) :: o INTEGER.

b. Note that a and b use pass-by-value since they are not optional.c. int b. INTENT(in) :: n.mcfarljm/fortwrap 3 sur 3 https://github. Arrays FUNCTION inner_prod(n. const int* c=NULL. Object(int n.b) END FUNCTION inner_prod generates a method of the "utility class" FortFuncs (the utility class is used to wrap functions that do not operate on a derived type): static int inner_prod(const std::vector<int>* a. OPTIONAL :: c. float val). These wrappers are particularly powerful when using swig with ‐c++ ‐keyword . const int* d=NULL).a. REAL. INTENT(in). Optional Arguments FUNCTION add_mixed(a. INTENT(in) :: val ALLOCATE(o%x(n))     o%x = val END SUBROUTINE value_ctor SUBROUTINE object_dtor(o) TYPE(Object) :: o IF(ALLOCATED(o%x)) DEALLOCATE(o%x) END SUBROUTINE object_dtor END MODULE m will generate multiple constructors for the C++ class Object : Object(int n). b(n) INTEGER :: y   y = DOT_PRODUCT(a. since the optional parameters can then be passed by keyword in the target language Known Issues Scalar character arguments not wrapped correctly (generated code won't compile) Old-style dummy argument definitions that do not include :: are not recognized Enumerators are not wrapped correctly if some names within a set are made private GitHub . The Fortran destructor object_dtor will automatically be called by the C++ destructor.d INTEGER :: y   y = a+b IF (PRESENT(c)) y = y + c IF (PRESENT(d)) y = y + d END FUNCTION add_mixed generates the following method: static int add_mixed(int a. INTENT(in) :: a.b INTEGER. a(n).b) RESULT(y) INTEGER. const std::vector<int>* b).d) RESULT(y) . Passing NULL (which is the default) indicates that the argument is not provided. The optional arguments c and d use pass-by-reference.