4.5 Using fpp

4.5.1 Source files

fpp operates on both fixed and free form source files. Files with the (non-case-sensitive) extension ‘.f’, ‘.ff’, ‘.for’ or ‘.ftn’ are assumed to be fixed form source files. All other files (e.g. those with the extension ‘.ff90’) are assumed to be free form source files. These assumptions can be overridden by the -fixed and -free options. Tab format lines are recognised in fixed form.

A source file may contain fpp tokens. An fpp token is similar to a Fortran token, and is one of:

4.5.2 Output

Output consists of a modified copy of the input plus line numbering directives (unless the -P option is used). A line numbering directive has the form
#line-number file-name
and these are inserted to indicate the original source line number and filename of the output line that follows.

4.5.3 Directives

All fpp directives start with the hash character (#) as the first character on a line. Blank and tab characters may appear after the initial ‘#’ to indent the directive. The directives are divided into the following groups:

4.5.4 Macro definition

The #define directive is used to define both simple string variables and more complicated macros:

#define name token-string

This is the definition of an fpp variable. Wherever ‘name’ appears in the source lines following the definition, ‘token-string’ will be substituted for it.

#define name([argname1[,argname2]...]) token-string

This is the definition of a function-like macro. Occurrences of the macro ‘name’ followed by a comma-separated list of arguments within parentheses are substituted by the token string produced from the macro definition. Every occurrence of an argument name from the macro definition's argument list is substituted by the token sequence of the corresponding macro actual argument.

Note that there must be no space or tab between the macro name and the left parenthesis of the argument list in this directive; otherwise, it will be interpreted as a simple macro definition with the left parenthesis treated as the first character of the replacement token-string.

#undef name

Remove any macro definition for name, whether such a definition was produced by a -D option, a #define directive or by default. No additional tokens are permitted on the directive line after the name.

The macro NAGFOR is defined by default.

4.5.5 Including external files

There are two forms of file inclusion:
#include "filename"
and
#include <filename>

Read in the contents of filename at this location. The lines read in from the file are processed by fpp as if they were part of the current file.

When the <filename> notation is used, filename is only searched for in the standard “include” directories. See the -I and -Y options above for more detail. No additional tokens are permitted in the directive line after the final ‘"’ or ‘>’.

4.5.6 Line number control

#line-number ["filename"]

Generate line control information for the next pass of the compiler. The line-number must be an unsigned integer literal constant, and specifies the line number of the following line. If "filename" does not appear, the current filename is unchanged.

4.5.7 Conditional selection of source text

There are three forms of conditional selection of source text:
  1.  #if condition_1
       block_1
     #elif condition_2
       block_2
     #else
       block_n
     #endif
    
  2.  #ifdef name
       block_1
     #elif condition
       block_2
     #else
       block_n
     #endif
    
  3.  #ifndef name
       block_1
     #elif condition
       block_2
     #else
       block_n
     #endif
    

The “#else” and “#elif” parts are optional. There may be more than one “#elif” part. Each condition is an expression consisting of fpp constants, macros and macro functions. Condition expressions are similar to cpp expressions, and may contain any cpp operations and operands with the exception of C long, octal and hexadecimal constants. Additionally, fpp will accept and evaluate the Fortran logical operations .NOT., .AND., .OR., .EQV., .NEQV., the relational operators .GT., .LT., .LE., .GE., and the logical constants .TRUE. and .FALSE..