nag_chname95 is the NAGWare f95 Tools name changer. This tool systematically changes names in Fortran source file(s).
If a filename with no extension is provided the tool will look for a file with the extension `.f95', and if that does not exist, for a file with the extension `.f90'.
If a file has the extension `.f90' or `.f95', it will be assumed to contain free format Fortran code. If a file has the extension `.f', `.for', `.f77', or `.ftn', the file is assumed to contain fixed format Fortran code. The options -fixed and -free may be used to override this behaviour.
The input file is backed up to infile.original and the output file replaces the input file.
Include files are expected to exist in the current working directory or in a directory named by the -I option.
Non-standard Equivalent Fortran 95 Intrinsic CDABS(A) ABS(A) DCMPLX(X,Y) CMPLX(X,Y,KIND=KIND(0d0)) DCONJG(Z) CONJG(Z) DIMAG(Z) AIMAG(Z) DREAL(Z) REAL(Z) or DBLE(Z)
FLAGS OLDSTRING NEWSTRING
where ``OLDSTRING'' is the string to be replaced. ``NEWSTRING'' is the string with which it should be replaced and ``FLAGS'' indicates to which area of the program the changes should be applied. No spaces are allowed in FLAGS. If ``OLDSTRING'' or ``NEWSTRING'' is a regular expression containing spaces (or ``NEWSTRING'' is a zero length replacement string) it must be surrounded in single quotes. Spaces are only useful in search and replacement strings that are applied to comments and strings. If the string contains a single quote this must be preceded by ``\''. In Fortran strings, an embedded quote, i.e.~two quotes in the source text, is stored as one quote. On output this is converted back to two quotes.
FLAGS takes the form of a string of `t's and `f's in the following layout.
<names><comments><strings><case-fold><regex>
thus ``tffff'' will change only names, ``tftff'' will change both names and strings.
A typical line might look like this:-
tffff OLD_VAR NEW_VAR
which will replace ``OLD_VAR'' with ``NEW_VAR'' in names only. In direct replacement, see below, names are not case-sensitive so all such names will be changed.
`f's to the right may be omitted, thus
tffff ABC XYZ
is equivalent to
t ABC XYZ
The <names> and <strings> flags turn on or off replacement in names and strings, respectively. If <case-fold> is true, case folding is applied and the search string will be matched irrespective of case. The <regex> flag may be set independently to interpret each change request as a regular expression (t) or a direct replacement (f).
When operating on strings and comments in direct replacement mode the tool matches words delimited by white space or characters other than alphanumerics, dollar sign and underscore.
Regular expressions used with names should not start with the metacharacters ``^'' or end with ``$''. All regular expressions applied to names have the beginning of line metacharacter prepended and the end of line metacharacter appended.
The program contains both a regular expression and a direct replacement mode. Many of the features of the two techniques are different and so they are discussed separately in the next two sections. It is much better to use the direct replacement rather than regular expressions where possible as it is likely to be much faster.
Both direct replacement and regular expressions may be specified in the same control file. The direct replacements are performed before the regular expression matches. If a direct replacement is made on a token or word no attempt is made to match any regular expressions on that token or word. Otherwise all regular expressions are applied to that token or word in the order specified and subsequent regular expressions are hence applied to the results of previous substitutions.
Direct replacement
This replaces a whole word (or identifier) with another whole word (or identifier).
Where an identifier is being replaced, the resulting case will be the same as any other identifier, as specified in the polish options file. Where a word is in a string or comment, the case matches that of the search string, as far as is possible. The case of change requests is not important and the `case folding' switch has no effect with `Direct replacement' mode.
Regular expressions
Regular expressions, based on GNU emacs and Unix egrep, may contain any of the following metacharacters:
any single character . beginning of line ^ end of line $ zero or more repeats * one or more repeats + zero or one repeat ? any character in set [...] any character not in set [^...] escape character \ tag field, see below \(...\) recall nth tag field \n tab character \t word break \b
Escape Character
The escape character (see table above) is used to introduce special characters, e.g. tag field recall. It may also be used to quote special characters to be used. For example, `\$' is the dollar sign.
Sets of Characters
A string of characters enclosed in square brackets `[ ]' matches any character in the string unless the first character is a `^', when the regular expression matches any character not in the string (other than newline). The string of characters may be abbreviated to a character range of the form a-z, 0-9, P-Y etc.
Tag Fields
It is possible to tag up to 9 character fields in the regular expression that can be recalled in any order in the replacement text. Tag fields are opened and closed using the metacharacter listed above. Tag fields may be nested but may not overlap; the fields are numbered 1 to 9 in the order in which they are opened. Tag field 0 is the whole matched pattern. In the replacement text the tag fields are recalled using the metacharacter shown above followed by the tag field number.
Word Break
The metacharacter `\b' matches a transition between alpha-numeric characters and non-alpha-numeric characters or vice versa.
Copyright, Numerical Algorithms Group, Oxford, 1997-2001