fotran2cpp

Automatic Fortran to C++ conversion

1. 安装fable环境

Pre-requisites:

  1. Please have a Linux environment, bash shell.

  2. Please create a working directory

    1
    2
    export WORK=<new working directory>
    cd ${WORK}
  3. Download source code:

    1
    2
    wget https://raw.githubusercontent.com/cctbx/cctbx_project/master/libtbx/auto_build/bootstrap.py --no-check-certificate
    python bootstrap.py hot update --builder=cctbx

Create and configure a conda environment:

1
2
3
4
5
6
7
8
9
10
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh --no-check-certificate
chmod u+x Miniconda2-latest-Linux-x86_64.sh
./Miniconda2-latest-Linux-x86_64.sh # tested with conda 4.5.11
# please install in directory ${WORK}/miniconda2
# no, do not prepend Miniconda2 to .bashrc

source miniconda2/etc/profile.d/conda.sh
conda create -y --name fable36 python=3.6
conda activate fable36
conda install six future

Create and configure FABLE:

1
2
3
4
5
6
7
mkdir build36
cd ${WORK}/build36
python ../modules/cctbx_project/libtbx/configure.py fable
# python ../modules/cctbx_project/libtbx/configure.py --enable_cxx11 fable # support C++11 standard
source ${WORK}/build36/setpaths.sh
cd ${WORK}/build36; make; cd ${WORK}
cd ${WORK}/build36; make; cd ${WORK}

Test FABLE in a new login shell (bash, cd ${WORK}):

1
2
3
4
5
source miniconda2/etc/profile.d/conda.sh
conda activate fable36
source ${WORK}/build36/setpaths.sh
mkdir test36; cd test36
libtbx.run_tests_parallel module=fable nproc=Auto

[!NOTE]

Not yet tested with MacOSX

Also works with Python 2.7 (change 3.6 to 2.7)

2. 使用fable

[!IMPORTANT]

fable comes with the C++ fem Fortran EMulation library. The entire fem library is inlined and therefore very easy to use: simply add -I/actual/path/fable or similar to the compilation command.

先启动上面创建好的python环境

1
2
3
source miniconda2/etc/profile.d/conda.sh
conda activate fable36
source ${WORK}/build36/setpaths.sh

之后开始转换代码

1
fable.cout your_fortran_code.f --namespace=example > example.cpp

编译新生成的C++代码

1
g++ example.cpp -I ${WORK}/fable -I ${WORK}/fable/modules/cctbx_project

[!NOTE]

其他问题可以参阅 https://cci.lbl.gov/fable/