General Syntax of a Macro
A macro is composed of two parts: a macro-name and a definition. A macro name
is an alphanumeric character string starting with an alphabetic character and
terminating with a colon. A macro name must not exceed 20 characters in length
and may only contain alphanumeric characters (a-z, 0-9).
A macro definition has a wide variety of forms. It may be 0 to 500 characters
in length (this may be increased via the RFPP macro maxbuf:), and may represent
a static character string or an expression that changes with each
invocation.
Each macro name in the input source code is replaced by its definition in the
Fortran output. The macro facility enables complex 'definitions' to be inserted
into the Fortran output via the 'name' invocation. To facilitate the definition
of macros, and other associated macro functions, the preprocessor provides a
variety of 'inbuilt' macro facilities.
Before describing these in detail it is necessary to define the general
syntactical form of a macro as it is applied. It is:
macro-name(arg1,arg2,...argN)
A macro may have from zero arguments (generally referred to as a 'static'
macro) up to a maximum of nine.
Before a macro can be applied, it must be defined. This is done using the
inbuilt RFPP macro macro:. In the macro definition, macro arguments appear as
the digraphs $1,$2,...$9. When a macro in the ratmac code is processed, its
arguments argN replace the digraphs in the stored definition. This occurs in
'dynamic' forms of the macro.
Before proceeding with explicit definitions, here are some simple examples of
macros.
The static macro cname: is defined as 'BILL' by the command,
macro:(cname:,BILL)
Thereafter any occurrence of cname:
in the ratmac code will be replaced by
BILL
in the Fortran output.
Another static macro resolution: defines the resolution parameter as the value
macro:(resolution:,0.00005)
Let us now consider a dynamic macro. The macro swap: is defined as
macro:(swap:,Q=QX($1);QX($1)=QX($2);QX($2)=Q)
The occurence of swap:(J,K+1)
in the ratmac code causes RFPP to output
Q=QX(J)
QX(J)=QX(K+1)
QX(K+1)=Q
into the Fortran code. In another part of the ratmac code this macro may be
invoked as swap:(KEY+5,INDEX-1)
and this causes RFPP to generate the Fortran code
Q=QX(KEY+5)
QX(KEY+5)=QX(INDEX-1)
QX(INDEX-1)=Q