Skip to main content


Figure 3 | Source Code for Biology and Medicine

Figure 3

From: Automatic Fortran to C++ conversion with FABLE

Figure 3

Example illustrating the handling of common variants by emulating the Fortran compile-time allocation mechanism at runtime in C++. (a) Two Fortran subroutines with variant uses of common block all. (b) Fragment from FABLE-generated C++ code adding placeholders for the all common variant and bookkeeping variables for the two subroutines to the common struct (which is the type of the cmn object). (c) Fragment from FABLE-generated C++ code defining function sub1. The FEM_CMN_SVE macro defines the is_called_first_time and sve variables. The latter manages both original Fortran SAVE variables and the function-specific bookkeeping for common variants. The mbr objects are temporary objects collecting information about variable types and array sizes. This information is used by all.allocate to allocate the required memory. The all.bind calls define array references to the memory area of the common block for local use in the function. (The FEM library guards against improper allocations that could invalidate existing references in other functions.) The common-variant mechanism shown in the example is meant to provide a general approach for obtaining a first working C++ version of a program. The disproportional length of the generated C++ code in the example highlights why it can be important to incrementally modify the Fortran sources in convert-build-test cycles, as described in section 3.1.

Back to article page