A translator from Fortran90/Fortran77(ISO/IEC 1539:1991) to C++
Fortran is an efficient tool in scientific calculation. However sometimes translating old fortran codes to C++ will enable more programming abstraction, better GUI framework support, higher performance IDE and easier interaction.
This translator is not intended to improve existing codes, but to make convenience for those who need features of C++ and remain fortran traits and performance as much as possible.
-
Convert Fortran90/Fortran77 code to C++14
-
Parse codes mixed with fixed form and free form automaticlly
-
C++ implemetation of some Fortran's type and functions
-
Generated C++ code remains abstract level of the origin code
e.g. implied-do will not expand to a for-loop directly, but to a
ImpliedDo
struct
The whole project, including both the translator itself and fortran standrad library implementation is distributed under GNU GENERAL PUBLIC LICENSE Version 2
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Calvin Neo
Copyright (C) 2016 Calvin Neo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- MSVC(e.g. Visual Studio 2015)
- win_flex(win_flex_bison 2.4.5, flex 2.5.37)
- win_bison(win_flex_bison 2.4.5, bison 2.7)
- boost(1.60)
- build boost
bjam --toolset=msvc-14.0 address-model=64
- configure boost
- Add boost_dir directory to additional include library
- Add boost_dir/libs and boost_dir/stage/lib to additional library directory
- On the Project menu, choose Project Dependencies.
- Select Custom Build Tools
- Add /src/grammar/custom_build_rules/win_flex_bison_custom_build.props
You can get Visual C++ Build Tools here(Not available now) or here
All built production will be in /bin
Run /build/winmake.cmd to get a x64 Release binary
Open /vsbuild/CFortranTranslator.sln
- g++(e.g. g++ 5.4.0)
- bison
- boost
Install boost by
sudo apt-get install libboost-all-dev
Install bison by
sudo apt-get install bison
cd build && make
make install
for90std is a simple implementation of fortran's library and is yet to be done
for90std requires compiler support at least C++14 standard(with several C++17 std functions)
With the following statement to include for90std module
#include "for90std/for90std.h"
cpptest is a C++ project template for you to test for90std.
-f file_name : translate file_name into C++
**Currently, Unicode encoding is not supported**
-d : use debug mode
-C : use c-style array
-F 90/77 : specify Fortran standard, by default the translator accept a mixed Fortran77/90 codes
- Use the following command to generate target C++ code
CFortranTranslator.exe -Ff demos/helloworld.f90 > target.cpp
- Build target.cpp, modify
#include "../for90std/for90std.h"
to ensure you include the right path of for90std library. You can either use /cpptest/winmake.cmd to build your code, or build them in cpptest project.
Several demos are provided in /demos.
Run /demos/merge_test.py to generate a *.form.test
file by merging codes from all .for
/.f90
files in a certain folder. Then you can convert the merged Fortran code into C++.
Several demos are provided in /demos/for90std. Make sure you have google-test library before test.
Only fatal errors hindering parsing will be reported by translator.
Debuging origin fortran code or generated C++ code is recommended.
see /docs/brief.md
see /docs/Develop.md to have an general understanding of implementation of this project.