Versions Compared

Key

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

...

Components

The "makeincludes" program is replaced by the following components:

Anchor
pythonscript
pythonscript
Python script

The "makeincludes" program was used to parse src/xbeachlibrary/params.F90 and src/xbeachlibrary/spaceparams.tmpl to find all input parameters and output variables respectively. The new templating system uses a Python script located in scripts/generate.py to parse the Fortran code. Also, the spaceparams.tmpl file is replaced by the src/xbeachlibrary/variables.F90 file. The main reason is that the Python script then only needs to parse Fortran code and not also a custom template format as used in the original spaceparams.tmpl file.

After parsing the relevant Fortran code the Python script defines two dictionaries (equivalent of Matlab's struct): "parameters" and "variables" that hold all the input parameters and output variables respectively, including their properties like rank, size, type and description. These dictionaries are used to parse the templates stored in src/xbeachlibrary/templates/ and generate the include files necessary to compile XBeach.

Anchor
templates
templates
Templates

Templates are written in Fortran and therefore have the F90 file extension. Each template file will result in a single include file that has the INC file extension and will be written in the src/xbeachlibrary/ directory. To add an include file simply add a template file to the src/xbeachlibrary/templates/ directory and it will be picked up by the Python script. Templates define the Fortran code that is repeated in include files. Additional template markers define how the code is repeated using snippets of Python code. The Mako template engine is used to do so (see http://www.makotemplates.org).

...

The definition starts with a Fortran variable type. The following types are supported: character, logical, double precision, integer and real. Then, separated by commas, the variable may be declared "allocatable" and must be declared "target". Two colons ("::"), the name and number of dimensions follow. The line ends with a comment, indicated by the "!". A comment starts with the variables units between brackets ("[" and "]") followed by a description of the variable. The comment ends with a JSON object that defines the fields "shape", "standard_name" and "broadcast" representing the shape of the variable in terms of XBeach dimensions s%nx+1, s%ny+1, s%nd, s%ngd, etc, the netCDF standard name according to the CF convention and a MPI broadcast type ("b" for "broadcast" and "d" for "distribute"). It is possible to add other fields to the JSON object. All values will be available during parsing of the Fortran templates through the "variables" dictionary. Be aware that the JSON part of the comment should be strict JSON format (e.g. only double quotes, no single quotes).

...

The writelog functions are also considered repetitive and therefore also generated using a template. You can add writelog functions by adding a format code to the "formats" variable in the src/xbeachlibrary/templates/writelog.f90 and src/xbeachlibrary/templates/writeloginterface.f90 templates (e.g. "aiaiafai"). The necessary functions and interfaces are generated accordingly.

Anchor
pythondeps
pythondeps
Python dependency

Compiling XBeach now depends on Python to generate the include files. Python is shipped with all popular Unix distributions, therefore this is no problem for Unix users. For Windows users Python is not always available. Therefore the scripts/generate.py is compiled as Windows executable so Windows users do not need Python to compile XBeach. Only when the scripts/generate.py script is modified the executable needs to be recompiled on a Windows machine with Python and the "distutils", "mako" and "py2exe" packages installed. Compiling the executable is done from the command-line as follows:

...