Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Python code can be added to a template in between the "<%" and "%>" markers. Single line code can be preceded simply by a "%". Single Python variables can be added within Fortran code within "${" and "}" markers.

In this example the first 10 lines define a Python function that generates a Fortran code snippet to define the dimensions of a variable. The function is used on line 13. Line 13 is in fact the only Fortran code line in this template. Line 12 and 14 form a for-loop that loops over all variables defined in the "variables" dictionary provided by the Python script and holds all variables defined in src/xbeachlibrary/variables.F90. This include file will therefore contain a single line of Fortran code for each variable defined in src/xbeachlibrary/variables.F90. It is possible to use Python variables within the Fortran code by including the Python variable within "${" and "}" markers as done multiple times in line 13.Each line uses the "fortrantype", "rank" and variables "name" from the "variables" dictionary as is visible in line 13. The "rank" is used to generate a Fortran code snippet to define the variables dimensions.

The first few lines of the resulting include file will look as follows:

Code Block
languagetext
titlespacedecl.inc
    double precision, dimension(:,:),  pointer :: x
    double precision, dimension(:,:),  pointer :: y
    double precision, dimension(:,:),  pointer :: xz
    double precision, dimension(:,:),  pointer :: yz
    double precision, dimension(:,:),  pointer :: xu
    double precision, dimension(:,:),  pointer :: yu
    double precision, dimension(:,:),  pointer :: xv
    double precision, dimension(:,:),  pointer :: yv

More changes

A few other things changed in the XBeach code structure along with the new templating system as explained in the following subsections.

...