Package: zpp
zppThis is zpp, the Z Pre-Processor.Zpp transforms bash in a pre-processor for F90 source files.
It offers a set of functions specifically tailored to build clean Fortran90
interfaces by generating code for all types, kinds, and array ranks supported by
a given compiler.SyntaxZpp files are typically named*.F90.zpp.In these files, the lines that start with!$SHare interpreted as bash lines.
Other lines are copied as-is, except that variable substitution is operated as
in a double-quoted string, including bash commands${VAR}or$(command).
If inside a bash control block (if,for, etc.), the output generation obeys
the control statement.For example, this code:!$SH for GREETED in world universe multiverse ; do
print *, "Hello ${GREETED}"
!$SH doneWould produce the following result:print *, "Hello world"
print *, "Hello universe"
print *, "Hello multiverse"Support functionsPredefined bash functions, variable and code can be provided in.zpp.shfiles
that can be included with#!SH source <filename>.zpp.sh.Beware: a file NEEDs to have the.zpp.shextension to be included from
zpp.Zpp provides a standard library of functions tailored to build clean Fortran90
interfaces by generating code for all types, kinds, and array ranks supported by
a given compiler.zpp_str_repeatFound inbase.zpp.shOutputs a string multiple times.Parameters:the string to Repeatthe lower bound of the iterations (inclusive)the upper bound of the iterations (inclusive)the string separatorthe string starterthe string enderRepeats string$1($3-$2+1) times, separated by string$4inside$5$6.If the number of repetitions is negative, the result is empty.If$1contains the '@N' substring, it will be replaced by the iteration
number (from$2to$3).example:#!SH source base.zpp.sh
zpp_str_repeat v@N 5 7 '...' '<<' '>>'
zpp_str_repeat w@N 1 1 '...' '<<' '>>'
zpp_str_repeat x@N 1 0 '...' '<<' '>>'output:<<v5...v6...v7>>
<<w1>>zpp_str_repeat_reverseFound inbase.zpp.shOutputs a string multiple times in reverse order.Parameters:the string to Repeatthe upper bound of the iterations (inclusive)the lower bound of the iterations (inclusive)the string separatorthe string starterthe string enderRepeats string$1($2-$3+1) times, separated by string$4inside$5$6.If the number of repetitions is negative, the result is empty.If$1contains the '@N' substring, it will be replaced by the iteration
number (from$2to$3, i.e. upper to lower).example:#!SH source base.zpp.sh
zpp_str_repeat_reverse v@N 5 7 '...' '<<' '>>'
zpp_str_repeat_reverse w@N 1 1 '...' '<<' '>>'
zpp_str_repeat_reverse x@N 1 0 '...' '<<' '>>'output:<<v7...v6...v5>>
<<w1>>ZPP_FORT_TYPESFound infortran.zpp.shThe list of types supported by the fortran compiler as zpp:typeIDs.The compiler ID should be provided inZPP_CONFIGasconfig.<ID>.
The supported predefined IDs are:Gnu,Intel,PGIandXL.
You can also provide definitions for an additional compiler by definingZPP_FORT_TYPESin a file namedconfig.<ID>.zpp.sh.If you use cmake, it will automatically generate such a file for your compiler
and defineZPP_CONFIGso you don't have to handle it.zpp_fort_array_descFound infortran.zpp.shOutputs an assumed shaped array descriptor of the provided size.Parameters:the size of the assumed shaped arrayexample:#!SH source fortran.zpp.sh
integer:: scalar$(zpp_fort_array_desc 0)
integer:: array1d$(zpp_fort_array_desc 1)
integer:: array2d$(zpp_fort_array_desc 2)output:integer:: scalar
integer:: array1d(:)
integer:: array2d(:,:)zpp_fort_ptypeFound infortran.zpp.shOutputs the type associated to a zpp:typeID.Parameters:a zpp:typeIDexample:#!SH source fortran.zpp.sh
!$SH for T in ${ZPP_FORT_TYPES} ; do
$(zpp_fort_ptype $1)
!$SH doneexample output:CHARACTER
COMPLEX
COMPLEX
INTEGER
INTEGER
INTEGER
INTEGER
LOGICAL
REAL
REALzpp_fort_kindFound infortran.zpp.shOutputs the kind associated to a zpp:typeID.Parameters:a zpp:typeIDexample:#!SH source fortran.zpp.sh
!$SH for T in ${ZPP_FORT_TYPES} ; do
$(zpp_fort_kind $1)
!$SH doneexample output:1
4
8
1
2
4
8
1
4
8zpp_fort_typeFound infortran.zpp.shOutputs the full type (with kind included) associated to a zpp:typeID.Parameters:a zpp:typeIDadditional attributes for the typeexample:#!SH source fortran.zpp.sh
!$SH for T in ${MY_CHAR_TYPES} ; do
$(zpp_fort_type $1)
$(zpp_fort_type $1 "len=5")
!$SH doneexample output:CHARACTER(KIND=1)
CHARACTER(KIND=1,len=5)zpp_fort_sizeofFound infortran.zpp.shOutputs the size in bits associated to a zpp:typeID.Parameters:a zpp:typeIDzpp_fort_io_formatFound infortran.zpp.shOutputs an IO descriptor suitable for a zpp:typeID.Parameters:a zpp:typeIDZPP_HDF5F_TYPESFound inhdf5_fortran.zpp.shA list of zpp:typeIDs supported by HDF5.hdf5_constantFound inhdf5_fortran.zpp.shOutputs the HDF5 type constant associated to a zpp:typeID.Parameters:a zpp:typeIDexample:#!SH source hdf5_fortran.zpp.sh
!$SH for T in ${ZPP_HDF5F_TYPES} ; do
$(hdf5_constant $1)
!$SH doneexample output:H5T_NATIVE_INTEGER
H5T_NATIVE_REAL
H5T_NATIVE_REAL
H5T_NATIVE_CHARACTERCommand-line interfaceZpp basic usage is as follow:Usage: zpp [Options...] <source> [<destination>]
  use `zpp -h' for more info

Preprocesses BASH in-line commands in a source file

Options:
  --version        show program's version number and exit
  -h, --help       show this help message and exit
  -I DIR           Add DIR to search list for source directives
  -o FILE          Place the preprocessed code in file FILE.
  -D OPTION=VALUE  Set the value of OPTION to VALUECMake interfaceSupport is provided for using zpp from CMake based projects, but you can use
it from plain Makefiles too.There are two ways you can use zpp from your CMake project:withadd_subdirectory: include zpp in your project and use it directly from
there,withfind_package: install zpp and use it as an external dependency of your
project.CMake subdirectory usageUsing zpp withadd_subdirectoryis very simple.
Just copy thezppdirectory in your source and point to it withadd_subdirectory(zpp).
Thezpp_preprocessthen becomes available to process zpp files.This is demonstrated inexample/cmake_subdirectory.CMake find usageUsing zpp withfind_packageis no more complex.
If zpp is installed, just add afind_package(zpp REQUIRED).
Thezpp_preprocessthen becomes available to process zpp files.This is demonstrated inexample/cmake_find.GMake usageUsing zpp from a GNU Makefile is slightly less powerful than from CMake.
The types and kinds supported by the Fortran compiler will not be automatically
detected.
Predefined lists of supported types for well known compilers are provided
instead.To use zpp from a Makefile, include theshare/zpp/zpp.mkfile (either from an
installed location or from a subdirectory in your project).
You can then set thezpp_COMPILER_IDvariable to the compiler you use and.F90files will be automatically generated from their.F90.zppequivalent.
ThezppFLAGSvariable is automatically passed to zpp similarly toCFLAGSorCXXFLAGSforccandcxx.This is demonstrated inexample/cmake_makefile.InstallationZpp can be installed using the usual python way withsetup.py../setup.py --helpThe cmake approach is deprecated.FAQQ. Isn't zpp redundant with assumed type parameters?A.
The assumed type parameters functionality allows to implement part of what can
be done with zpp (support for all kinds of a type). However as of 2013 it was
not correctly supported on most compilers installed on the supercomputers.In addition, many things can be done with zpp but not with assumed type
parameters, such as support for variable array rank or small variations of the
code depending on the kind.