Templated Fortran Source#
Where Fortran modules are needed which are identical except for minor changes such as “type” and “kind” they are not stored as source but as templated source which is used to generate the source.
Template Files#
These files have the .t90 extension or .T90 if they are to produce a
.F90 source file.
They contain Fortran source but with named replacement sites marked with
{{name}}.
For example:
module special_{{thing}}_mod
implicit none
private
type, public :: {{thing}}_type
{{type}} :: value
end type {{thing}}_type
end module special_ {{thing}}_mod
Templaterator#
The tool used to process template files is called “templaterator”. It is invoked with a template file, and output file and one or more substitutions:
Templaterator -o <output filename> -s <substitution> <template filename>
The output filename itself is a template and may include {{name}}}
substitution markers. For instance, if producing type dependent code, you may
specify the output filename to be some/directory/special_{{type}}_mod.
The substitutions are key value pairs separated by and equals sign. The left
hand is the key used to refer to the value and the right hand is the value
itself. To create a substitution for type, used above, specify
type=integer.
Inclusion in a Project#
In order to use templated source in a project it must be generated by the
project’s build system. For applications this involves adding the Templaterator
call to the build target of the top-level Makefile. For libraries it is
added to build/import.mk, see Library Import.
Warning
At the moment the Inputs project uses a build system incapable of running source generators. Instead it relies on the test suite to build the source.
Thus adding new templated source requires the modification of the
Applications repository test suite. See
rose-stem/app/template/bin/template.